Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint 2010 Client Object Model - Large Library - Find item without iteration

I have a large document library (at the moment ~6000 documents) and I need to find a document based on a custom field value (custom column on the library).

Is there a way of getting this document back without iterating through all 6000 documents?

I understand that an iteration must occur at some point, but I would prefer it to happen on the SharePoint server side, rather than transfer them all to the client side then cherry pick the document.

Thanks

like image 794
Russell Avatar asked Oct 24 '22 07:10

Russell


1 Answers

You can query Sharepoint. You issue a CAML query which is executed on the server and brings back only items that match the criteria that you specified. You specify the name of the custom column to search on and you specify the value to find. For efficiency , you can ask only for a few fields back (document url for example). So, you do not need to iterate over documents in the list to find the item.

You can find some discussion here: http://msdn.microsoft.com/en-us/library/ee956524.aspx and you can also find examples how to do it from javascript or silvelight.

Example CAML:

        CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml =
        @"<View>
            <Query>
              <Where>
                <Eq>
                  <FieldRef Name='FileLeafRef'/>
                  <Value Type='Text'>Test.docx</Value>
                </Eq>
              </Where>
              <RowLimit>1</RowLimit>
            </Query>
          </View>";
like image 57
KJRB Avatar answered Oct 31 '22 10:10

KJRB