2
votes

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.

1
see this link, may be useful blog.halan.se/post/…Amir

1 Answers

0
votes

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.