简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM