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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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;
}