Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm trying to crawl over site documents and find their properties. While I was able to do the first part, using something like

        ClientContext clientContext = new ClientContext("http:xxx");
        clientContext.Credentials = new NetworkCredential(...);
        Web oWebsite = clientContext.Web;
        clientContext.Load(oWebsite);
        clientContext.ExecuteQuery();

        List tlist = site.Lists.GetByTitle("Shared Documents");
        clientContext.Load(tlist);
        clientContext.ExecuteQuery();

        CamlQuery query = new CamlQuery();
        ListItemCollection items = tlist.GetItems(query);
        clientContext.Load(items);
        clientContext.ExecuteQuery();

        foreach (ListItem item in items)
        {
          ... do something with item.File...
        }

I could not find a way to get to the file properties, something which is possible with SharePoint Server, e.g.

SPDocumentLibrary lib = (SPDocumentLibrary)web.Lists["Documents"];
foreach (SPListItem item in lib.Items)
{
  if (item.File.Properties.Contains("_Comments"))
  {
    Console.WriteLine("File {0} contains comment {1}.", 
      item.File.Name, item.File.Properties["_Comments"]);
  }
 }

Is there any way to do this, without actually copying the file from the SharePoint?

Thank you in advance

share|improve this question

3 Answers 3

You will need to fetch the properties explicitly:

clientContext.Load(
                items,
                lstitems => lstitems.Include(
                item => item["_Comments"],
             ));
share|improve this answer
    
Hm, it does not work for me either: I used this code CamlQuery query = new CamlQuery(); ListItemCollection items = tlist.GetItems( query ); clientContext.Load(items , lstitems => lstitems.Include( item => item["_Comments"] )); but I'm always getting the following exception : Column 'Comments' does not exist. It may have been deleted by another user. /DEV/DEV1/Shared Documents –  Igor Jul 16 '12 at 15:23

Try this:

clientContext.Load(items, 'Include(_Comments)'); 

instead of

clientContext.Load(items); 
share|improve this answer
1  
That's actually the code for the JavaScript Client Object Model. @Igor you will have to use Linq when working with the .net client object model. (I am adding the code in an answer below due the lack of formatting in comments) –  Vardhaman Deshpande Jul 9 '12 at 17:04
    
Oops, didn't notice it was .NET. :) –  Steve Lineberry Jul 9 '12 at 17:28

I think, in your foreach loop, you need to load each file.

   clientContext.Load(item.File);
   clientContext.ExecuteQuery();
   if (item.File.Properties.Contains("_Comments"))
   { 
     Console.WriteLine("File {0} contains comment {1}.", 
     item.File.Name, item.File.Properties["_Comments"]);
   }

Cheers !

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.