Monday, 10 October 2011

Check if the Infopath form is deployed in SharePoint 2010 site using object model


If you need to verify that a Infopath form is deployed in your SharePoint site using the object model, you can use the very handy Microsoft.Office.InfoPath.Server.Administration namespace.

You can call the method below to list out all the infoptah form templates available in SharePoint 2010 farm and then check if your desired form is installed.

private void GetAllInfoPathForms()
{
DataTbale dt;
FormsService _formsService;

SPFarm localFarm = SPFarm.Local;
try
{
//Get the local infopath service name
_formsService = localFarm.Services.GetValue(FormsService.ServiceName);

foreach (FormTemplate fTemplate in _formsService.FormTemplates)
{
dt.Rows.Add(fTemplate.DisplayName.ToString(), fTemplate.FormId.ToString(), fTemplate.Locale.ToString());
int intRow = dt.DefaultView.Find("yourInfoPathTemplateName");
if(intRow != null)
{
string _found = "Found the Form";
}

}
}
catch (Exception ex)
{
MessageBox.Show("An error occurred: " + ex.Message.ToString());
}
}

Ads by Google

No comments:

Post a Comment