Introduction
Recently, I needed to interact with InfoPath 2007 Forms from the Forms Library in MOSS 2007. So, looking around the web and after compiling some information, I made a Helper to serialize and deserialize the components of an InfoPath Form from/to objects in C#. The idea is that using a Workflow, I can capture or set the value of any component of the form.
Background
We are going to use two methods for manipulate the InfoPath's control. First, using the classic XML with the XPathNavigator
and the XmlDocument
object model. We can get and set values with this method. The other will be using the class exported from the InfoPath Form code using XSD.exe. For the first method, I took the idea from: http://www.bizsupportonline.net/infopath2007/programmatically-retrieve-infopath-form-from-sharepoint.htm[^]. For the other method, I used: http://msdn.microsoft.com/en-us/library/bb251017.aspx[^].
Partial Codes
We can use this Helper without MOSS 2007, just like a simple form:
string sStatus = string.Empty;
string sFileSource = string.Empty;
sFileSource = "InfoPathForm.xml";
InfoPathHelper.FileName = sFileSource;
sStatus = InfoPathHelper.Value("Status");
InfoPathHelper.SetValue("Status", "En Progreso ...");
misCampos InfoPathForm =
(misCampos)InfoPathHelper.DeserializeFile(sFileSource, typeof(misCampos));
sStatus = InfoPathForm.Status;
Or we can use this Helper with MOSS 2007 in conjunction with Workflows:
SPSite site = new SPSite("http://miportal.intranet");
SPWeb web = site.AllWebs["Sistemas/Incidentes"];
SPList list = web.Lists["FomulariosInfoPath"];
SPListItem item = list.Items[0];
InfoPathHelper.SPFileName = item;
sStatus = InfoPathHelper.Value("Status");
InfoPathHelper.SetValue("Status", "En Progreso ...");
misCampos InfoPathFormMoss =
(misCampos)InfoPathHelper.DeserializeFile(item.File, typeof(misCampos));
sStatus = InfoPathFormMoss.Status;
The Project
The solution was made with Visual Studio 2008 in a host running Microsoft Office SharePoint Server 2007. Also is included the InfoPath form. Happing coding!