I use a caml query to check whether a file exits in a given folder. When I run the application it gives an error saying "Value does not fall within expected range". What am I doing wrong. I have added the code below. Thanks in advance.
string Librery = "Scans";
string folder = @"/"+Librery+"/"+textBox1.Text.Trim();
ClientContext clientContext = new ClientContext("http://test/sites/LegalDocs");
newFile.Url = "Pens.docx";
if (!FileExists(clientContext, Librery, newFile.Url, folder))
{
Microsoft.SharePoint.Client.File uploadFile = ii.Files.Add(newFile);
clientContext.Load(uploadFile);
clientContext.ExecuteQuery();
}
public bool FileExists(ClientContext clientContext, String list, String fileName, String relativeDir)
{
List DocumentsList = clientContext.Web.Lists.GetByTitle(list);
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='Recursive'>
<Query>
<Where>
<Eq>
<FieldRef Name='FileLeafRef'></FieldRef>
<Value Type='Text'>" + fileName + @"</Value>
</Eq>
</Where>
</Query>
</View>";
camlQuery.FolderServerRelativeUrl = relativeDir; ;
ListItemCollection listItems = DocumentsList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
return listItems.Count > 0;
}