2

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

有没有更好的方法使用 infopath 2010 或 sharepoint 2010 对象模型。

4

1 回答 1

0

是的,您可以使用 InfoPath 2010 OM 从模板中提取任何文件(要求代码是实际 IP-Form 中的 CodeBehind),使用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 文件)中,然后您可以使用它更轻松地进行操作。

于 2011-11-11T08:01:43.797 回答