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?
Asked
Active
Viewed 2,188 times
1 Answers
5
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;
}

Community
- 1
- 1

Daniel Halan
- 584
- 7
- 8
-
Great, I see that your new to the site, do press the up arrow at the left side of the question to indicate that the answer was helpful/useful :) – Daniel Halan Mar 02 '12 at 08:26