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 existing on a SharePoint server, I use this approach , but it extracts the template files in the server temp directory, for which we may not have write permissions. Is there a better solution for this?

+2
source share
1 answer

You just modify the CAB library, which can extract the template file into memory, like this one,

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

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

full code would look 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;
}
+5
source

Source: https://habr.com/ru/post/1709398/


All Articles