0

I have a document libraries. I want to filter the documents based on some of the filter conditions. Its really difficult to generate the Caml query dynamically which will give the actual result depending on the filter values.

The filter values are the columns from Document libraries. Linq to Sharepoint support List, but is there anyway by which i can query document libraries too?

user1899731
  • 61
  • 2
  • 5

1 Answers1

0

You can use Linq To Sharepoint after using the SPMetal tool to generate your entities.

http://www.codeproject.com/Articles/399927/SharePoint-2010-LINQ-and-SPMetal

This is an example of what Sharepoint Link looks like:

using (SiteEntitiesDataContext context = new SiteEntitiesDataContext("http://appes-pc"))
{
    var result = context.Manager.Where(m => m.Country == "USA");

    foreach (ManagerItem manager in result)
    {
        Console.WriteLine(manager.Name);
    }
}

Or alternatively if you want to use CAML there is a very good CAML builder utility called:

Camlex.NET - http://camlex.codeplex.com/

So this:

<Where>
  <Eq>
    <FieldRef Name="Status" />
    <Value Type="Text">Completed</Value>
  </Eq>
</Where>

Can be written as:

string caml =
    Camlex.Query()
        .Where(x => (string)x["Status"] == "Completed").ToString();
Luis
  • 5,979
  • 2
  • 31
  • 51