使用Web服务从Sharepoint列表下载
本文关键字:列表 下载 Sharepoint Web 服务 使用 | 更新日期: 2023-09-27 18:27:28
我正在编写一个程序,在该程序中我使用sharepoint的列表Web服务和Web客户端。C#的DownloadFile方法下载列表中的所有文件。该列表包含1800个文件,这些文件显示在18页中,导致每页有100个文件。然而,我的代码只下载前10页中的文件(1800个文件中有1000个文件)。有人知道问题出在哪里吗?这是我的代码
XmlNode ndListItems = null;
XmlDocument xdoc = new XmlDocument();
XmlNode ndQuery = xdoc.CreateNode(XmlNodeType.Element, "Query", "");
XmlNode ndViewFields = xdoc.CreateNode(XmlNodeType.Element, "ViewFields", "");
XmlNode ndQueryOptions = xdoc.CreateNode (XmlNodeType.Element, "QueryOptions", "");
ndQuery.InnerXml = "";
ndViewFields.InnerXml = "";
ndQueryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>";
ndListItems = list.GetListItems(ListName, "", ndQuery, ndViewFields, "1000", ndQueryOptions, null);
if (ndListItems!=null)
{ foreach (XmlNode node in ndListItems.ChildNodes) { if ( node.Name=="rs:data")
{ string[] foldernames = new string[node.ChildNodes.Count];
for (int i = 0; i < node.ChildNodes.Count; i++) { if (node.ChildNodes[i].Name == "z:row" && node.ChildNodes[i].Attributes != null)
{ string fileurl= node.ChildNodes[i].Attributes["ows_ServerUrl"].Value;
string filename = node.ChildNodes[i].Attributes["ows_LinkFilename"].Value;
string contenttype = node.ChildNodes[i].Attributes["ows_ContentType"].Value;
string copysource = serverAddress + fileurl;
Uri copyUrl = new Uri(copysource);
if (contenttype=="Folder")
{ foldernames[i] = filename;
Directory.CreateDirectory(copyDestination+ filename); continue; } try {
int index = FolderNamseContain(filename, copysource, foldernames);
if (index != -1) { wc.DownloadFile(copysource, copyDestination + foldernames[index] + "''" + filename);
report.Write(fileurl);
report.WriteLine();
report.Flush(); }
您的问题在这里:
ndListItems = list.GetListItems(ListName, "", ndQuery, ndViewFields, "1000", ndQueryOptions, null)
您指定的行限制为1000个项目。更改为:
ndListItems = list.GetListItems(ListName, "", ndQuery, ndViewFields, "2000", ndQueryOptions, null)