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 have a document library MyLib and i need to find specified file in it .

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

how can I specify my Document Library?

Thank you!

share|improve this question
add comment

1 Answer

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>";    
try
            {
                using (SPSite objSite = new SPSite("sitename"))
                {
                    using (SPWeb objWeb = objSite.OpenWeb())
                    {
                        // Building a query
                        SPQuery query=new SPQuery();
                        query.Query=camlQuery;

                        // 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"]);
                        }

                    }
                    Console.ReadLine();
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Occured:", ex.Message);
            }
            Console.ReadLine();
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
1  
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
1  
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
add comment

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.