If you use the SharePoint Object Model to access InfoPath forms in SharePoint, you have the option to either use the SPList or the SPFolder class to retrieve and loop through InfoPath forms that are stored within a SharePoint Form Library.
While the SPFolder class offers more direct access to the physical XML file of an InfoPath form stored in a SharePoint Form Library, you can use the SPList class to retrieve other useful information about the form and its metadata, such as for example, the InfoPath form template (XSN) that a form is based on (accessible through the ContentType property of the list item).
Use the SPList class to loop through InfoPath forms
The following code sample makes use of the SPList, SPListItem, and SPFile classes to loop through InfoPath forms, which are stored within a SharePoint Form Library:
using (SPSite site = new SPSite("http://<SharePoint_Site_URL>"))
{
using (SPWeb web = site.OpenWeb())
{
SPList formsLib = web.Lists["FormsLib"];
if (formsLib != null)
{
foreach (SPListItem item in formsLib.Items)
{
SPFile ipForm = item.File;
string fileName = ipForm.Name;
}
}
web.Close();
}
site.Close();
}
where FormsLib is the name of a SharePoint Form Library on the site.
Use the SPFolder class to loop through InfoPath forms
The following code sample makes use of the SPFolder and SPFile classes to loop through InfoPath forms, which are stored within a SharePoint Form Library:
using (SPSite site = new SPSite("http://<SharePoint_Site_URL>"))
{
using (SPWeb web = site.OpenWeb())
{
SPFolder formsLib = web.Folders["FormsLib"];
if (formsLib != null)
{
foreach (SPFile ipForm in formsLib.Files)
{
string fileName = ipForm.Name;
}
}
web.Close();
}
site.Close();
}
where FormsLib is the name of a SharePoint Form Library on the site.

Comments to this post were closed 30 days after it was published.