2

I have a document library in Sharepoint 2010 and stored the infopath 2010 forms template (XSN file). Is there a way to programmatically (using C# code) open the XSN using SharePoint Object Model or Infopath 2010 object Model. I want to open the .XSL file and change some text and then repackage the file. I know there are some assemblies like Microsoft.Deployment.Compression and Microsoft.Deployment.Compression.Cab which will extract the XSN (cab file) and unpack them to a temp folder. But this will require some elevated permission etc., etc.,

Is there a better way of doing it using infopath 2010 or sharepoint 2010 object model.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Kannan Karmegam
  • 651
  • 4
  • 12
  • 24
  • see this link, may be useful http://blog.halan.se/post/How-to-create-a-new-Form-from-Template-in-a-Form-Library-programmatically.aspx#comment – Amir Jan 31 '12 at 22:45

1 Answers1

0

Yes, you can extract any file from the template with the InfoPath 2010 OM (requires that the code is CodeBehind in an actual IP-Form) with the OpenFileFromPackage Method like this:

public XmlDocument ExtractFromPackage(string fileName)
{            
    try 
    {
        XmlDocument doc = new XmlDocument();

        using (Stream stream = Template.OpenFileFromPackage(fileName))
            doc.Load(stream);

        return doc;
    } 
    catch (Exception ex)
    { 
        throw new Exception(string.Format("Error extracting '{0}': {1}", 
            fileName, ex.Message), ex);
    }
}

The code takes the stream from the packaged file and loads into a XmlDocument (which can only be used for XSL files) which you then can use to do manipulations more easily.

int32
  • 1,687
  • 1
  • 10
  • 6