仅使用caml查询动态下载文件,而不使用get folder方法

时间:2019-06-05 20:40:00

标签: c# file sharepoint caml

我想下载多个文件,例如使用正则表达式,其中用户通过变量提供文件名,并在caml查询中传递该文件名,并且可以循环访问列表URL。这个caml查询区域有点新。有什么建议可以实现吗?

    camlQuery.ViewXml = @"<View> 

           <Query>

              <Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + fileToDownload + @"</Value></Eq></Where>

           </Query>

            <ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /></ViewFields>

     </View>"; 
                        Web web = clientContext.Web;
                         clientContext.Load(web);
                         clientContext.Load(web.Lists);
                         List list = clientContext.Web.GetList(listUrl);
                         //clientContext.Load(list);
                         //clientContext.ExecuteQuery();
                          ListItemCollection listItems = list.GetItems(camlQuery);
                         clientContext.Load(listItems);
                         clientContext.ExecuteQuery();

                         foreach (var item in listItems)
                         {
                             if (item.FileSystemObjectType == FileSystemObjectType.File)
                             {
                                 Console.WriteLine("This is file");
                             }
                             else if (item.FileSystemObjectType == FileSystemObjectType.Folder)
                             {
                                 Console.WriteLine("This is folder");
                             }

    camlQuery.ViewXml = @"<View> 

           <Query>

              <Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>" + fileToDownload + @"</Value></Eq></Where>

           </Query>

            <ViewFields><FieldRef Name='FileRef' /><FieldRef Name='FileLeafRef' /></ViewFields>

     </View>"; 
                        Web web = clientContext.Web;
                         clientContext.Load(web);
                         clientContext.Load(web.Lists);
                         List list = clientContext.Web.GetList(listUrl);
                         //clientContext.Load(list);
                         //clientContext.ExecuteQuery();
                          ListItemCollection listItems = list.GetItems(camlQuery);
                         clientContext.Load(listItems);
                         clientContext.ExecuteQuery();

                         foreach (var item in listItems)
                         {
                             if (item.FileSystemObjectType == FileSystemObjectType.File)
                             {
                                 Console.WriteLine("This is file");
                             }
                             else if (item.FileSystemObjectType == FileSystemObjectType.Folder)
                             {
                                 Console.WriteLine("This is folder");
                             }

我需要从FiletoDownload变量上的匹配模式下载文件,就像它的一样。它应该下载所有文件。

1 个答案:

答案 0 :(得分:0)

以下是代码段供您参考:

http://ec2-52-204-122-132.compute-1.amazonaws.com/API-Application