使用网络服务从共享点删除文件 [英] Deleting a file from sharepoint using web service

查看:55
本文介绍了使用网络服务从共享点删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Sharepoint 文档库中删除文件.我的应用程序是在 C# 中,它使用 sharepoint 的 web 服务.想知道如何做到这一点.提前致谢.

I am trying to delete a file from a sharepoint document library. My application is in C#, which uses the web services of sharepoint. Would like to know how this can be done. Thanks in advance.

推荐答案

使用 Web 服务删除 SharePoint 中的文档

1.将 Web 引用添加到 http://[您的站点]/_vti_bin/Lists.asmx

1.Add Web Reference to http://[your site]/_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);

我刚刚测试了这段代码并且运行良好.

I just tested this code and works well.

有关更多信息,请参阅以下链接

For more information please see following links

Lists.UpdateListItems 方法

如何:更新列表项

这篇关于使用网络服务从共享点删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆