Note that there are some explanatory texts on larger screens.

plurals
  1. POProgramatically upload XSN to SharePoint
    primarykey
    data
    text
    <p>I have a bunch of InfoPath form templates (xsn) which I want to upload to a SharePoint list programatically. My program has to upload these form templates to different lists based on predefined logic. When I upload the browser-enabled form templates (xsn) with my code, the forms do not work:</p> <pre><code>/// &lt;summary&gt; /// Uploads a file to the specified sharepoint list /// &lt;/summary&gt; /// &lt;param name="listName"&gt;&lt;/param&gt; /// &lt;param name="fileInfo"&gt;&lt;/param&gt; /// &lt;param name="listVersion"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public static bool UploadFile(string listName, FileInfo fileInfo, string listVersion) { WebRequest request = WebRequest.Create(fileInfo.URL); request.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; request.Method = "PUT"; byte[] buffer = new byte[1024]; using (Stream stream = request.GetRequestStream()) { using (MemoryStream ms = new MemoryStream(fileInfo.Bytes)) { for (int i = ms.Read(buffer, 0, buffer.Length); i &gt; 0; i = ms.Read(buffer, 0, buffer.Length)) stream.Write(buffer, 0, i); } } WebResponse response = request.GetResponse(); response.Close(); var client = new Lists.ListsSoapClient(); var batch = new XElement("Batch", new XAttribute("OnError", "Continue"), new XAttribute("ListVersion", listVersion), new XAttribute("PreCalc", "TRUE")); var method = new XElement("Method", new XAttribute("ID", "1"), new XAttribute("Cmd", "Update"), new XElement("Field", new XAttribute("Name", "ID")), new XElement("Field", new XAttribute("Name", "FileRef"), fileInfo.URL)); foreach (string key in fileInfo.Properties.Keys) { object value = fileInfo.Properties[key]; method.Add(new XElement("Field", new XAttribute("Name", key), fileInfo.Properties[key])); } batch.Add(method); var element = client.UpdateListItems(listName, batch); var code = element.Elements().First().Elements().First().Value; if (code != "0x00000000") throw new Exception(code); return true; } </code></pre> <p>It seems there is more to be done that just pushing a file stream into the list. </p> <p>Anyone have an idea how to do this?</p> <p><strong>EDIT</strong> More specifically, the error message I get is: <code>This form template is not enabled for viewing in the browser.</code></p> <p><strong>UPDATE</strong> When I publish the same form with Microsoft InfoPath it works.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload