要使用SharePoint Web Service从.NET获取文档列表,您需要遵循以下步骤:
http://your_sharepoint_site/_vti_bin/lists.asmx
。单击“添加引用”按钮,将Web引用添加到项目中。using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
public class SharePointHelper
{
private string _url;
private string _username;
private string _password;
public SharePointHelper(string url, string username, string password)
{
_url = url;
_username = username;
_password = password;
}
public List<string> GetDocumentList()
{
Lists lists = new Lists();
lists.Url = _url;
lists.Credentials = new System.Net.NetworkCredential(_username, _password);
XmlNode listData = lists.GetListItems("Documents", null, null, null, "0", null, null);
List<string> documentList = new List<string>();
foreach (XmlNode node in listData.SelectNodes("//rs:data/z:row", GetXmlNamespaceManager(listData)))
{
string documentName = node.Attributes["ows_FileLeafRef"].Value;
documentList.Add(documentName);
}
return documentList;
}
private XmlNamespaceManager GetXmlNamespaceManager(XmlNode node)
{
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(node.OwnerDocument.NameTable);
namespaceManager.AddNamespace("rs", "urn:schemas-microsoft-com:rowset");
namespaceManager.AddNamespace("z", "#RowsetSchema");
return namespaceManager;
}
}
SharePointHelper sharePointHelper = new SharePointHelper("http://your_sharepoint_site/_vti_bin/lists.asmx", "username", "password");
List<string> documentList = sharePointHelper.GetDocumentList();
foreach (string documentName in documentList)
{
Console.WriteLine(documentName);
}
注意:在实际项目中,您需要使用更安全的身份验证方法,例如使用ADFS身份验证或使用客户端证书进行身份验证。此外,您可能需要根据您的SharePoint版本和配置进行一些调整。