SharePoint ドキュメント ライブラリからファイルを削除しようとしています。私のアプリケーションは、sharepoint の Web サービスを使用する C# です。これを行う方法を知りたいです。前もって感謝します。
6266 次
2 に答える
2
Webサービスを使用してSharePointでドキュメントを削除する
1. Web参照をhttp://[あなたのサイト]/_vti_bin/Lists.asmxに追加します
2.削除するドキュメントのドキュメントID、ライブラリ名、およびURLが必要です
var spWebServiceLists = "http://[your site]/_vti_bin/Lists.asmx";
var listService = new Lists
{
Credentials = CredentialCache.DefaultCredentials,
Url = spWebServiceLists
};
string id = 10;
string library = @"Shared Documents";
string url = @"http://[your site]/Shared Documents/Test.docx";
string xml = "<Method ID='1' Cmd='Delete'>" +
"<Field Name='ID'>" + id + "</Field>" +
"<Field Name='FileRef'>" + HttpUtility.UrlDecode(url) + "</Field>" +
"</Method>";
/*Get Name attribute values (GUIDs) for list and view. */
System.Xml.XmlNode ndListView = listService.GetListAndView(library, "");
string strListID = ndListView.ChildNodes[0].Attributes["Name"].Value;
string strViewID = ndListView.ChildNodes[1].Attributes["Name"].Value;
/*Create an XmlDocument object and construct a Batch element and its
attributes. Note that an empty ViewName parameter causes the method to use the default view. */
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
batchElement.SetAttribute("OnError", "Continue");
batchElement.SetAttribute("ListVersion", "1");
batchElement.SetAttribute("ViewName", strViewID);
/*Specify methods for the batch post using CAML. To update or delete,
specify the ID of the item, and to update or add, specify
the value to place in the specified column.*/
batchElement.InnerXml = xml;
XmlNode item;
item = listService.UpdateListItems(library, batchElement);
このコードをテストしたところ、うまく機能しました。
詳細については、次のリンクを参照してください
于 2012-11-28T03:45:15.630 に答える
1
SharePoint 2010 を使用している場合は、CSOM を使用して SharePoint Web サービスにアクセスできます。このリンクは、crud 操作を実行するのに役立ちます。SharePoint 2013 を使用している場合は、CSOM API もあり、2010 と同様の機能を備えています。
于 2012-11-15T14:03:47.727 に答える