Welcome to Office Zealot Sign in | Join | Help

Some of our challenges: CAML, properties...

It's been an exciting 4 days. We are finally starting to have every item come togeher to form the nice site this is supposed to be.In another post, we'll show you how the tag cloud from Community Server looks.

This is how the Articles and News will look now:

The joys of CAML and SPQuery

Well, Sharepoint sure is fun! Much of its flexibility comes with a level of complexity that sometimes is hard to manage; but not to worry, in the end, everything ends up working.

One particular challenge is CAML and its use on list queries.

For example, the following code works: 

<Where>
<
And>
<
Eq><FieldRef Name="ADCStatus" /><Value Type="Text">Published</Value></Eq>
<
And><Eq><FieldRef Name="Region" LookupId="TRUE"/><Value Type="Lookup">{0}</Value></Eq>
<
And><Leq><FieldRef Name="ADCStartDate" /><Value Type="DateTime"><Today /></Value></Leq>
          <
Geq><FieldRef Name="ADCEndDate" /><Value Type="DateTime"><Today /></Value></Geq></And>
</
And>
</And>
</
Where>
<
OrderBy><FieldRef Name="ADCStartDate" Ascending="False" /><FieldRef Name="ADCName" Ascending="True" /></OrderBy>

But don't add the <Query> parent element, because if you do, you simply get bad results. You also need to be very careful with element names and attributes; while this is obvious (it is XML and case sensitive), one misplaced character will give you headaches.

There are tools out there that help you write CAML; nevertheless, the tools are still using Sharepoint to run the queries, and, sometimes, Sharepoint simply does not give you detailed error messages if there is an error in the query. Before you bang your head against the wall, just double check the query with extreme care.

Properties and the ToolPane
One -apparently common- mistake we made during web part development was to include old attributes (that applied to the old web part classes in Sharepoint 2003, and not to the current classes in WSS 3). So instead of:

[Personalizable, WebBrowsable, WebDisplayName("Region ID"), WebDescription("Enter the Region ID for this web part.")]

We used:

[ Browsable, DisplayName("Region ID"), Description("Enter the Region ID for this web part.")]

This caused some problems with the tool pane in Sharepoint. Fortunately we noticed our mistake after a few minutes and everything was fine again...

 

Published Wednesday, February 06, 2008 9:29 PM by omar2

Comments

No Comments
Anonymous comments are disabled