3

I'm using the SharePoint Managed Client Object Model API to retrieve files from SharePoint to my console app which is written in C#. My code (abbreviated here) looks something like this:

ClientContext clientContext = GetClientContext(sitePath);
Web rootWeb = clientContext.Web;

var files= rootWeb.GetFolderByServerRelativeUrl(relativeURL).Files;
clientContext.Load(files);
clientContext.ExecuteQuery();
// FileCollection files has no results

The returned FileCollection (files) has no results even though the folder specified (in the relativeURL) actually has a couple of files in it. When I run the bit of code below, the Folder object's ItemCount property is 2.

ClientContext clientContext = GetClientContext(sitePath);
Web rootWeb = clientContext.Web;

var folder = rootWeb.GetFolderByServerRelativeUrl(relativeURL);
clientContext.Load(folder);
clientContext.ExecuteQuery();

// folder.ItemCount == 2

I can't figure out why I can't seem to get the files. All the permissions seem OK. Are there any other gotcha's that exist in the API?

David Clarke
  • 12,888
  • 9
  • 86
  • 116
Mark Atkinson
  • 161
  • 2
  • 7

2 Answers2

3

I figured out my problem. My sitePath wasn't quite complete. I had part of the site prefixed to the relativeURL. So, I could create the site context and also get the folder but since the clientContext wasn't built completely with the site I wanted, I could never get the files.

Mark Atkinson
  • 161
  • 2
  • 7
1

I'm just starting myself, but my code looks just like yours, but I have this loop following it

...         
clientContext.ExecuteQuery();
foreach( File file in files )
{
Debug.WriteLine( file.ServerRelativeUrl + "\t Level: " + file.Level + "\t modified: " + file.TimeLastModified + "\t by: " + file.ModifiedBy.ToString() + "\t CheckInComment: " + file.CheckInComment + "\t UIVersionLabel: " + file.UIVersionLabel );
}
Luke
  • 11
  • 1