How to programmatically create an InfoPath form from an InfoPath XSN template

两盒软妹~` 提交于 2019-12-01 10:27:15
Daniel Halan

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

Minimum C# code to extract from .CAB archives or InfoPath XSN files, in memory

And then call, myCab.ExtractFile("template.xml", out buffer, out bufferLen);

the complete code would look something like

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!