I want to download multiple files say by using regex where user provides the file name through a variable and that gets passed in caml query and it can iterate through a list url. A bit new on this caml query zone. Any advice how to achieve it?
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");
}
I need to download the file from matching pattern on FiletoDownload variable like if its . it should download all files.