我遇到了一個問題,該問題是以編程方式創建並添加到SharePoint中的表單庫以打開InfoPath模板而不是以純XML格式打開的XML文檔Internet Explorer中的文檔。設置以編程方式創建的XML文檔以在SharePoint中使用InfoPath模板打開
基本上,我有一個Web服務,檢查數據庫,看看是否某些條件是真實的。如果是,則Web服務以編程方式創建一個XML文檔,該文檔具有與前面提到的InfoPath模板創建的文件相同的XML模式。通常的過程是,真正的用戶打開此InfoPath模板,填寫數據並單擊SUBMIT按鈕,該按鈕在幕後創建XML文檔並將其保存在表單庫中。當用戶進入表單庫以後查看該XML文檔時,該文檔將自動打開InfoPath模板(而不是在Internet Explorer中打開爲XML文檔)。
我試圖追查爲什麼從Web服務生成的XML文檔在這方面的行爲與從InfoPath生成的XML文檔的行爲不同。下面是我用來創建Web服務中的XML文檔的代碼片段:
//specify path to the SharePoint site and the form library
var clientContext = new ClientContext("http://urlToSiteContainingTheFormLibrary");
var site = clientContext.Web;
clientContext.Load(site);
var folder = site.GetFolderByServerRelativeUrl("FormLibraryNameHere");
clientContext.Load(folder);
clientContext.ExecuteQuery();
//create new file to add to the form library
var fci = new FileCreationInformation();
var encoding = new System.Text.UTF8Encoding();
//load the InfoPath document's XML schema from resources file
var baseXml = XElement.Load(new StringReader(Properties.Resources.BaseXml));
//fill out the appropriate elements and attributes of the XML here
//......
//
//set remaining properties of the new FileCreationInformation object
byte[] array = encoding.GetBytes(baseXml.ToString());
fci.Content = array;
fci.Overwrite = true;
fci.Url = "DocumentName"
//add the new file to the form library
var newFile = folder.Files.Add(fci);
clientContext.Load(newFile);
var item = newFile.ListItemAllFields;
clientContext.Load(item);
//set metadata for the xml file here
item["HTML_x0020_File_x0020_Type"] = "InfoPath.Document.3";
item["TemplateUrl"] =
"http://templateUrlHere/template.xsn?openin=preferclient&noredirect=true&xsnlocation=/templateLocation/template.xsn";
//set remaining item properties......
//update changes to the item
item.Update();
//commit the changes
clientContext.ExecuteQuery();
在這一點上,我的XML文檔被成功提交到我的表單庫,但是當我去打開它,它在Internet Explorer中以純XML格式打開,而不是使用我指定的模板。我會假設該項目的HTML_x0020_File_x0020_Type和TemplateUrl屬性將爲SharePoint指定足夠的信息,以知道需要使用InfoPath模板打開此文件,但也許還有一些其他屬性需要專門設置。有沒有人有類似問題的經驗?起初,我認爲我用於模板的URL是錯誤的,但是我直接從通過InfoPath模板創建的現有XML文檔中複製它,所以我不認爲這是問題(我忽略了任何真實在我上面的示例代碼中的URL和文件名,所以請忽略這些URL不正確的事實)。我正在繼續解決這個問題,但同時我認爲有人可能以前解決過這個問題,並可能提供一些見解。
非常感謝您提供任何答案,我感謝您提供的任何幫助。
你有沒有想過這個?我正在處理類似的問題,但使用SharePoint對象模型。我現在的嘗試是設置內容類型,但它似乎像它得到正確的內容類型...... –