SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a document library MyLib and i need to find specified file in it .

        query.Query = @"
                    <FieldRef Name='Title' />
                        <Value Type=" + name + 

how can I specify my Document Library?

Thank you!

share|improve this question
up vote 3 down vote accepted
const string camlQuery = @"<query><where><and><gt><fieldref name="Price"><value type="Number">1000</value></fieldref></gt><leq><fieldref name="Price"><value type="Number">10000</value></fieldref></leq></and></where><orderby><fieldref ascending="False" name="Price"></fieldref></orderby></query>";    
                using (SPSite objSite = new SPSite("sitename"))
                    using (SPWeb objWeb = objSite.OpenWeb())
                        // Building a query
                        SPQuery query=new SPQuery();

                        // Retrieving the data from the List
                        SPList objList=objWeb.Lists["Product List"];
                        SPListItemCollection items= objList.GetItems(query);

                        // Prinitng the header
                        Console.WriteLine("{0,-25} {1,-20} {2,-15} {3}", "Title", "Price", "Qunatity", "Is Available");

                        foreach (SPListItem objListItem in items)
                            Console.WriteLine("{0,-25} {1,-20} {2,-25} {3}", objListItem["Title"], objListItem["Price"],
                                                                             objListItem["Quantity"], objListItem["Is Available"]);


            catch (Exception ex)
                Console.WriteLine("Error Occured:", ex.Message);
share|improve this answer
thank you, and query will be like i mentioned above? query.Query = @" <Where> <Eq> <FieldRef Name='Title' /> <Value Type='Text'> "+ name + @"</Value> </Eq> </Where> "; – Lena Aug 30 '12 at 6:17
it should be like this i think u missed the <query> tag-- query.Query = @" <query><Where> <Eq> <FieldRef Name='Title' /> <Value Type='Text'> "+ name + @"</Value> </Eq> </Where></query>"; let me know if it not helps u – Rajesh Chowdary Aug 30 '12 at 6:24
You should NOT include the <Query> tag when assigning to SPQuery.Query – Per Jakobsen Aug 30 '12 at 8:01
I so much appreciated ! – Lena Aug 30 '12 at 9:06
Thanks Lena now i got 46 reputation i am new to share point i have only 2 days experiance your comments giving me some push up – Rajesh Chowdary Aug 30 '12 at 10:26

Your Answer


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.