2012-01-31 30 views
2

我需要創建與SharePoint服務器上存在一個XSN模板的InfoPath實例形式的解決方案創建一個InfoPath表單,我使用this approach但這種提取物對服務器的臨時目錄模板文件我們可能沒有寫入權限。有更好的解決方案嗎?如何以編程方式從InfoPath XSN模板

回答

5

你只需要改變的CAB-庫,一個可以提取模板文件存儲,因爲這一個,

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

然後調用,myCab.ExtractFile("template.xml", out buffer, out bufferLen);

完整的代碼看起來像

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

這對我很有幫助,謝謝。 – Amir 2012-03-02 01:01:43

+0

太好了,我看到你的新的網站,不要按向上箭頭的問題的左側,以表明答案是有幫助/有用:) – 2012-03-02 08:26:44

+0

感謝是我的朋友。 – Amir 2012-03-02 14:38:36

相關問題