2011-11-11 38 views
2

我在Sharepoint 2010中有一个文档库并存储了infopath 2010表单模板(XSN文件)。有没有通过编程方式(使用C#代码)使用SharePoint对象模型或Infopath 2010对象模型打开XSN的方法。我想打开.XSL文件并更改一些文本,然后重新打包该文件。我知道有一些程序集像Microsoft.Deployment.Compression和Microsoft.Deployment.compression.cab将提取XSN(cab文件)并将它们解压缩到临时文件夹。但是这需要一些提升权限等,以编程方式打开infopath模板文件(XSN)

有没有更好的方式来使用infopath 2010或SharePoint 2010对象模型。

+0

看到这个链接,可能是有用的http://blog.halan.se/post/How-to-create-a-new-Form-from-Template-in-a-Form-Library-programmatically.aspx#评论 – Amir

回答

0

是的,你可以提取与在InfoPath 2010 OM模板的任何文件(需要代码是在实际的IP表格代码隐藏)与OpenFileFromPackage方法是这样的:

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); 
    } 
} 

的代码需要来自打包文件的流并加载到XmlDocument(它只能用于XSL文件),然后您可以使用它更轻松地进行操作。

+0

谢谢安德烈亚斯。将尝试一下。 – Kannabiran