本文介绍了如何从 InfoPath XSN 模板以编程方式创建 InfoPath 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个从 SharePoint 服务器上存在的 XSN 模板创建 InfoPath 实例表单的解决方案,我使用的是 这种方法 但这会在我们可能不会的服务器临时目录中提取模板文件有写权限.有没有更好的解决方案?

I need a solution that creates an InfoPath instance form from an XSN template that exists on a SharePoint server, I am using this approach but this extracts template files on temp directory of server that we may not have write permission to. Is there better solution for this?

推荐答案

您只需将 CAB 库更改为可以将模板文件提取到内存的库,就像这个,

You just change the CAB-library, to one that can extract the template file to memory, as this one,

从内存中的 .CAB 档案或 InfoPath XSN 文件中提取的最少 C# 代码

然后调用,myCab.ExtractFile("template.xml", out buffer, out bufferLen);

完整的代码看起来像

private byte[] GetXmlForm(SPDocumentLibrary list) {
  byte[] data = null;
  SPFile file = list.ParentWeb.GetFile(list.DocumentTemplateUrl);


  Stream fs = file.OpenBinaryStream();
  try {
    data = new byte[fs.Length];
    fs.Read(data, 0, data.Length);
  } finally {
    fs.Close();
  }

  byte[] buffer;
  int bufferLen;
  CabExtract cab = new CabExtract(data);
  cab.ExtractFile("template.xml", out buffer, out bufferLen);

  return buffer;
}

这篇关于如何从 InfoPath XSN 模板以编程方式创建 InfoPath 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:46
查看更多