Monday, 2 December 2013

How to Use Greater Than and Less Than in CAML with Where

How to Use Greater than and Less than in CAML




SPQuery query = new SPQuery();
                    query.Query = @"<Where>
      <And>
         <And>
            <Or>
               <And>
                  <Geq>
                     <FieldRef Name='FromDate' />
                     <Value Type='DateTime'>2013-11-13T12:00:00Z</Value>
                  </Geq>
                  <Leq>
                     <FieldRef Name='FromDate' />
                     <Value Type='DateTime'>2013-12-03T12:00:00Z</Value>
                  </Leq>
               </And>
               <Geq>
                  <FieldRef Name='ToDate' />
                  <Value Type='DateTime'>2013-11-13T12:00:00Z</Value>
               </Geq>
            </Or>
            <Leq>
               <FieldRef Name='ToDate' />
               <Value Type='DateTime'>2013-12-03T12:00:00Z</Value>
            </Leq>
         </And>
         <Eq>
            <FieldRef Name='Column1' />
            <Value Type='Text'>f2</Value>
         </Eq>
      </And>
   </Where>";

Monday, 25 November 2013

Fetch Data using LINQ in Sharepoint programatically

Fetch Data using LINQ in Sharepoint



                    SPList List = web.Lists["abc"];
                     var checkin = from SPListItem p in List.Items
                                   //&& p["col1"].ToString().ToLower() ==facility
                                where  p["col2"].ToString().ToLower() ==val1.ToLower() && p["Room"].ToString().ToLower() == room  && Convert.ToDateTime(p["fromDate"].ToString()) >=dtIn && Convert.ToDateTime(p["FromDate"].ToString()) < dtOut
                   
                                 select p;