Thursday, January 29, 2009

Today in CAML query

I had to use [Today] in a CAML query. I tried configuring the query with the U2U Caml Query Builder 2007, this was the output:

<Where>
      <Eq>
         <FieldRef Name='Modified' />
         <Value Type='DateTime'>[Today-120Day(s)]</Value>
      </Eq>
</Where>

But this did not work when a tried to run the query in code (SPQuery). I used this query instead, and it worked fine:

<Where>
      <Eq>
         <FieldRef Name='Modified' />
         <Value Type='DateTime'><Today OffsetDays="-120"/></Value>
      </Eq>
</Where> 

Friday, December 5, 2008

SharePoint: Add a site collection policy to a content type programmatically

In this blogpost, I wrote about how to add a Policy to a content type programmatically.

I got a question by mail how I'd add a site collection policy to a content type in code.

This is the code that can do this:

using (SPSite site = new SPSite(http://server))

{

SPContentType contentType = null;

//get content type id

foreach (SPContentType type in site.RootWeb.ContentTypes)
{

if (type.Name == "test content type")
{
contentType = type;
break;
}
}

PolicyCatalog catalog = new PolicyCatalog(site);

if (catalog != null && catalog.PolicyList != null)
{

foreach (Policy p in catalog.PolicyList)
{

if (p.Name == "test site collection policy")
{

//todo: check if contenttype has already got a Policy; then delete the Policy first
Policy.CreatePolicy(contentType, p);
}
}
}
}

By the way

I don't think the policy on the content type is updated when you update the site collection policy.. I think this should be test very good! I tried this:
- create a site collection policy (in SharePoint UI)
- assign this site collection policy to your content type (in SharePoint UI)
- watch the PolicyItem.CustomData property on the Policy of your content type in code:
Policy pol = Policy.GetPolicy(contentType);

foreach (PolicyItem item in pol.Items)

{

Console.WriteLine(item.CustomData.ToString());

}

- Change your site collection policy (in SharePoint UI)

- Rewatch the PolicyItem.CustomData property on the Policy of your content type in code...

=> The CustomDatea property on the policy on my content type was NOT changed... This is pretty weird..

Thursday, October 23, 2008

Electrabel mailbevestiging

Toen ik via de site van Electrabel een vraag stelde, kreeg ik een bevestiging vanwege Luc Goossens, Sales Manager. Met vriendelijke groenten! :-D

screenshot van de mail:

electrabel

Tuesday, September 2, 2008

Download Google Chrome Beta

I've downloaded the Google Chrome Beta version, looks nice and it's very fast!