I need to query multiple document libraries and get a particular item's ID by matching the queried barcode value. I need the ID to update the metadata for that item using web services. All the document libraries are within the same site. What would be the best method to query for the item ID?
You can use a Data View Web Part with DataSourceMode="Crosslist" for this if you're looking for a "non-code" solution.
You can also use the Web Services themselves. Here's an example.
I think you can proceed by using SPSiteDataQuery. You can define its object and sets its properties to query libraries within a web and its child webs.
SPSiteDataQuery q = new SPSiteDataQuery(); q.Lists = "<Lists BaseType='1'/>"; q.Query = "<Where><Gt><FieldRef Name='ID' /><Value Type='Number'>0</Value></Gt></Where>"; q.Webs = "<Webs Scope='Recursive' />"; q.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='ID' />"'; q.RowLimit = 10;
The Webs Property Scope='Recursive: This will search the web on which you execute the query and recurse through any child webs.
The Lists Property
This defines what type of document libraries and lists WSS will search for your items. You can specify the exact type of list, the base type or even specific lists. Examples of the Lists property are...
"" As above, this will search all lists which are based on a 'Document Library. This is useful if you only want to find documents. Other values for BaseType include...
0 - Generic list - This will search all lists and not document libraries. 1 - Document Library 3 - Discussion Forum 4 - Vote or Survey 5 - Issues list
You can find more info here