user542499
user542499

Reputation: 11

CAML query for custom content type

Am looking for the same target mentioned in Daivd Hill post, but still can not get the custom content type my query is like;

string dateString = (DateTime.Now.Add(new TimeSpan(-5, 0, 0, 0, 0))).ToString("yyyy-MM-ddThh:mm:ssZ");
string q= String.Format("Where And"+"Eq FieldRef Name='ContentTypeId'/" + "Value Type='Text'0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D08/Value /Eq"+
"Eq FieldRef Name='Created'/" +
"Value Type='DateTime'{0} /Value /Eq ", dateString+ " /And /Where");

SPSiteDataQuery query = new SPSiteDataQuery();

query.Query= q;

After that what should I do -> where should I execute the query against , as am trying to get against the content type , most of the examples I found was about built-in lists like task announcement..etc

in the query am trying to get the specific custom content type based on its ID that is created for ex 5 days ago

Thanks if u have any idea for help, or can u give the example of what ur solution look like thanks Azo

Upvotes: 1

Views: 6078

Answers (1)

Maksymilian Mulawa
Maksymilian Mulawa

Reputation: 277

Something like this worked well for me, but I was querying the list.

string dateInCorrectFormat = SPUtility.CreateISO8601DateTimeFromSystemDateTimeDateTime.Now.AddDays(-5));
SPQuery query = new SPQuery();
//Query below
query.Query = String.Format( .... ,    dateInCorrectFormat);
SPListItemCollection items = list.GetItems(query);

<Where>
      <And>
          <BeginsWith>
               <FieldRef Name='ContentTypeId' />
               <Value  Type='ContentTypeId'>0x0100XCustomContentypeIdHereX</Value>
          </BeginsWith>
          <Lt>
               <FieldRef Name='Created'/>
               <Value Type='DateTime' IncludeTimeValue='TRUE'>{0}</Value>
         </Lt>
    </And>
</Where>

Hope this helps.

Upvotes: 1

Related Questions