Click here to Skip to main content
15,036,823 members
Articles / Desktop Programming / Win32
Posted 6 Feb 2009


7 bookmarked

InfoPath 2007 Helper for MOSS 2007

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
6 Feb 2009GPL31 min read
This article is about how to get or set values of an InfoPath form.


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.


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:[^]. For the other method, I used:[^].

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";

// Get the value of the field Status from the XML
// representing the InfoPath form
InfoPathHelper.FileName = sFileSource;
sStatus = InfoPathHelper.Value("Status");

// Set the value of the field Status
InfoPathHelper.SetValue("Status", "En Progreso ...");

// We can also get the value of any field by deserializating 
// the InfoPath form with the method DeserializeFile from our Helper
misCampos InfoPathForm = 
  (misCampos)InfoPathHelper.DeserializeFile(sFileSource, typeof(misCampos));
sStatus = InfoPathForm.Status;

Or we can use this Helper with MOSS 2007 in conjunction with Workflows:

// Go to the specific item (the InfoPath form) in our MOSS
SPSite site = new SPSite("http://miportal.intranet");
SPWeb web = site.AllWebs["Sistemas/Incidentes"];
SPList list = web.Lists["FomulariosInfoPath"];
SPListItem item = list.Items[0];

// Set the filename representing the InfoPath form
InfoPathHelper.SPFileName = item;

// Get the value for the field Status from the form
sStatus = InfoPathHelper.Value("Status");

// Set a value to a field of the form
InfoPathHelper.SetValue("Status", "En Progreso ...");

// Another way to get the value of a field in the InfoPath
// form with deserailization. This only allows getting values
// but no setting any value.
// The object InfoPathFromMoss will have all the fields of the form
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!


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Javier Ibarra
Systems Engineer San Antonio International - Pride
Argentina Argentina
Desde chico mi fasinacion hacia las computadoras marcaron mi camino profesional que iba a recorrer en los proximos dias de mis vida. Ingeniero en Sistemas, recibido en la UADE en el 2005, mi abocacion hacia la programacion en tecnologias de Microsoft hicieron hoy en dia desarrollarme como Arquitecto o Lider Tecnico en proyectos con tecnologias .Net. No solo la programacion es uno de mis pasiones, sino tambien todo lo referente a Infraestructura con productos de Microsoft. Actualmente estoy desenvolviendome como SharePoint Specialisst en una empresa petrolera lideando con sistemas montados sobre dicha tecnologia. Casado con mi hermosa mujer Cecilia quien es el motor que empuja mis ambiciones y ayuda a mejorarme dia a dia.

Comments and Discussions

-- There are no messages in this forum --