Workflow, Collaboration, Enterprise Content Management

Feed your CAML some IntelliSense so it doesn't bite you in the you-know-what!

by John Holliday 18. January 2009 22:44

camldotnet_80x80 As every SharePoint developer knows, the CAML is an ornery beast.  Get too close - it'll spit at you, and as soon as you get knee-deep in the hot sands of SharePoint-land, it's just a matter of time before it bites you in the ass!

But wait!  There's hope for all you erstwhile CAML-geeks!

Announcing the CAML.NET IntelliSense project

I've added a new component to the CAML.NET toolset that aims to help you tame that sometimes finicky, but ever-popular and oh-so-useful CAML language.

Click here to download the CAML.NET.Intellisense installer.

You probably already know how to add the SharePoint schemas to Visual Studio so you get IntelliSense when editing CAML files.  If not, here's a link to a great article by my friend Andrew Connell that walks you through the procedure.

This is a good first step, but we can take it even further by copying the core schema files and then extending them so they provide more information.  Specifically, we can add the detailed guidance from the SDK that is scattered all over the Internet and that developers seem to have a hard time finding. 

Let's face it - even with an up to date set of bookmarks, who wants to go searching all over the place for that missing tidbit that tells you just what that obscure attribute is for when you're right in the middle of building the CAML for your feature?  If you're like me, this quickly becomes a major distraction.  Hard enough to stay focused in the first place!

Using Annotated Schemas

The main idea behind the CAML.NET IntelliSense project is to extend the core schemas in two ways:

  1. Gather as much information as possible about each element and attribute and place it into xs:annotation elements so that it pops up in context while editing; and
  2. Identify and replace as many xs:string types as possible with enumerated types so the valid values for each attribute also popup in context while editing.

For example, using the core WSS schemas directly, we get a drop-down like the following while editing a Field element:

PlainSchema

That's better than nothing, but it doesn't say what the attribute is for, so unless we're already familiar with it, we have to refer back to the SDK either online or in the CHM file.  On the other hand, using the enhanced annotated WSS schema, we can provide more information in context.  We only need to refer to the SDK documentation when we really need it.  Most of the time, we just need a hint, which is what Intellisense is all about, right?

EnhancedSchema

Extending the Core Schemas with Enumerated Types

In addition to annotating the schemas with the corresponding SDK documentation for each element, we can go one step further and change the plain vanilla xs:string types to custom enumerated types so we get the list of valid choices for the attribute values.  This comes in very handy and also helps to eliminate those nasty little typos that can be *really* hard to find (and the CAML gets mighty snippy about).

There are lots of places in the SDK documentation where the expected attribute values are listed in the description, but are not enumerated in the schema.  This again means that we have to go digging through the documentation to discover what SharePoint expects the attribute values to be.  This can be an enormous waste of time - even if you have a pretty good idea of what the values are.  Who can keep all that detail in their head?

So, I've tried to find and enumerate as many attribute values as I could so they are available at your fingertips when you need them.  Each enumeration is also annotated, so you get contextual help for the available values as shown below.

CamlIntellisense

Here's another example that shows the enumeration of list template types when adding a ListInstance element to a feature.  This is a biggie.  How many times have you had to hunt down the table of list template type identifiers?

ListTemplateTypeEnum

Installing the Enhanced Schemas

The CAML.NET IntelliSense download package includes an MSI installer that copies the extended schemas into the local Visual Studio schema cache, so all you have to do is run the installer and then close and re-open Visual Studio.  The current version handles both Visual Studio 2005 and 2008.

Note: If you're already using the wss.xsd schema from the 12 hive, you should remove the previous catalog file from the Visual Studio schema cache.  You may also have to fiddle with your IDE settings a bit because Visual Studio somehow remembers the previous schema settings and adds both the old and the new schemas for files that have already been edited, event after you have removed the old catalog file.  This can interfere with the new catalog file you've just installed.  In the worst case, you will have to choose "don't use this schema" from the "schemas" dialog for files you have already started editing.

As you can imagine, there are a LOT of elements and attributes to deal with.  I've made a pretty good start at addressing the most frequently used items, and I'll continue to add more annotations as my schedule permits.  If you find missing or incorrect annotations, please drop me a line or leave a comment and I'll update the schema. 

Now you can ride that CAML high in the saddle and head on out to the SharePoint.  You know - the oasis?  Right next to the 12 hive!  See you there!

"The camel has a single hump,
The dromedary two;
Or else the other way around,
I'm never sure.  Are you?"

- Ogden Nash

Stay tuned for CAML.NET 2.0!

Comments

1/21/2009 4:54:46 AM

Mads Nissen

Great idea John! Instant download & install. Estimating 2hr timesaver per developmentweekSmile

Keep up the good work!

mads

Mads Nissen no

1/22/2009 7:53:08 AM

Jarret Franklin

Bravo John!

Jarret Franklin us

1/30/2009 1:01:46 PM

Mehul Bhuva

Wonderfull tool John sir...

Your contributions to the Sharepoint community are unmatched. I have written a small Case Study on ECM using MOSS Collaboration Portal based on a real-life implementation. Here is the link: mehulbhuva.blogspot.com/.../...nterprise-wide.html

I have given your reference, as you helped me out with the SP Dispose issue and CAML querries.

Mehul Bhuva in

1/30/2009 1:24:22 PM

John Holliday

Thanks, Mehul!

John Holliday us

2/1/2009 3:03:44 PM

trackback

Trackback from Blog del CIIN

WSS 3.0 & MOSS: Recopilatorio de enlaces interesantes (XXV)!

Blog del CIIN

2/1/2009 3:14:43 PM

pingback

Pingback from jcgonzalezmartin.wordpress.com

WSS 3.0 & MOSS: Recopilatorio de enlaces interesantes (XXV)! « Pasión por la tecnología…

jcgonzalezmartin.wordpress.com

2/2/2009 11:17:52 PM

Sherman Woo

Hi John, thanks for the efforts in getting this time-saver to the rest of us.

Just thought I'd mention, for those of us who are using x64 environments, after you install the MSI, I found the "CAML.NET.IntelliSense.xml" file located here: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Xml\Schemas. If you look inside the file, however, you'll find that the catolog is looking for the schema here: file://C:/Program Files/CAML.NET/IntelliSense/caml.xsd.

On my system, I had to change that schema reference to ...C:/Program Files (x86)/.... Once I did that, fired up VS, all was well. Looking forward to zipping through my SP schema files now! Awesome!

Keep up the great work!

Sherman Woo ca

2/4/2009 8:41:46 PM

John Holliday

Thanks for the catch, Sherman! I've updated the MSI so that it now handles 64 bit installations.

John Holliday us

2/4/2009 8:50:16 PM

Bjørn Furuknap

Mr. Holliday, you are a true hero!

Bjørn Furuknap no

2/5/2009 11:18:53 AM

trackback

Trackback from Vlad-Point Master Chief

CAML.NET IntelliSense para SharePoint

Vlad-Point Master Chief

2/6/2009 3:04:51 PM

trackback

Trackback from Blog Tech

Caml.Net Intellisense pour sharepoint.

Blog Tech

2/7/2009 5:46:50 PM

trackback

Trackback from Mirrored Blogs

CAML et Intellisense

Mirrored Blogs

2/9/2009 7:37:07 AM

Oskar Austegard

Another excellent contribution. Thanks!

Oskar Austegard us

2/10/2009 5:34:31 AM

BinaryJam

Absolutely Sterling work there.

I edited mine to include this, I added the Format Attribute and I believe that it is of subtype DisplayFormat. Hope Im right and hope it helps.


<xs:complexType name="QueryColumnDefinition" mixed="true">
<xs:complexContent>
<xs:extension base="LookupColumnDefinition">
<xs:sequence />
<xs:attribute name="Default" type="xs:string" />
<xs:attribute name="URLEncode" type="TRUEFALSE" />
<xs:attribute name="Format" type="DisplayFormat" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

BinaryJam gb

2/15/2009 1:47:19 PM

trackback

Trackback from Andrew Connell [MVP MOSS]

Getting even better IntelliSense for CAML when doing SharePoint projects

Andrew Connell [MVP MOSS]

2/16/2009 12:32:42 AM

trackback

Trackback from Michael Blumenthal Blog

Twitter ROI == Minutes! AKA Better CAML Intellisense

Michael Blumenthal Blog

2/16/2009 6:07:46 AM

Anne Onyx-Mouse

I had to turn off other schemata using the schema dialog for all files I had touched before installing this, since intellisense disappeared altogether for those files. After this it works great!

Anne Onyx-Mouse

2/16/2009 12:37:35 PM

Bharat

CAML.NET IntelliSense works fine with VS2005 but what to do to get it work on VS2008? I added Schema file in property window while creating a new xml file and adding xmlns reference to sharepoin, but intellisense did not work.
Thank you in advance for your answer.
Bharat.

Bharat us

2/18/2009 2:27:19 PM

pingback

Pingback from emadmagdy.wordpress.com

Good Links, February 18, 2009 « Emad’s Weblog

emadmagdy.wordpress.com

2/21/2009 5:36:08 AM

Pedro Mateus

This is a time saver! Thanks alot Smile

Pedro Mateus pt

3/1/2009 8:09:05 AM

Peso

Hi John!
Cool, but I have trouble using caml.xsd. VS 2008 is working just fine with the other four .xsd-files but as soon as I am adding caml.xsd (I added all five for testing purpose by hand) intellisense is not working anymore. Any suggestions would be great.

Thanks a lot and best regards!

Peso de

3/2/2009 3:03:03 AM

trackback

Trackback from Gunnar Peipman's ASP.NET blog

Links 2009-02-28

Gunnar Peipman's ASP.NET blog

3/14/2009 8:24:48 PM

pingback

Pingback from praveenmodi.com

SharePoint - Add IntelliSense when editing CAML files in WSS v3 / MOSS 2007 | Tech Cocktail

praveenmodi.com

3/18/2009 12:24:29 AM

John D. Sanders

Fantastic work.

John D. Sanders us

3/18/2009 4:04:16 AM

John Holliday

Hi Bharat,

If you run the MSI file, it will install itself automatically for both VS2005 and VS2008, and it works on 32bit and 64bit systems. Then you have to restart Visual Studio. If all else fails, check that the files exist in the following locations:

%programfiles%\caml.net\intellisense\caml.xsd
%programfiles%\Microsoft Visual Studio 9.0\xml\Schemas\CAML.NET.IntelliSense.xml

If you have any other schema file associated with the "http://schemas.microsoft.com/sharepoint/" namespace, then Intellisense will stop working. To check, create a new XML file and setup the schema (this must be exactly correct - case sensitive), then open the "schema" dialog from the properties window. Sort by namespace and make sure that the only schema checked is the CAML.XSD file described above.

Cheers,
John

John Holliday us

3/18/2009 4:05:13 AM

John Holliday

Hi Peso,

There can be only one xsd definition loaded for any given namespace/entity pair. You have to remove the other ones in order for Intellisense to work. If VS detects two definitions for the same entity, it doesn't know which one to load and therefore does not load anything.

Hope this helps,
John

John Holliday us

5/11/2009 4:56:47 PM

Ayman El-Hattab

Genuis Smile

Ayman El-Hattab eg

6/23/2009 6:46:53 AM

Thorsten Hans

Very nice!

Works fine.

Thorsten Hans de

6/25/2009 6:10:35 AM

Lars Nielsen

Great piece of work, helps us all! Many thanks.

Lars Nielsen gb

8/25/2009 10:44:48 AM

pingback

Pingback from johanleino.wordpress.com

Intellisense support for unity (and wss/moss) xml files « Johan Leino

johanleino.wordpress.com

10/19/2009 4:36:27 PM

pingback

Pingback from blog.domcosgrove.com

Dom Cosgrove Blog » Top SharePoint Dev Utility Apps

blog.domcosgrove.com

Comments are closed
Twitter Facebook Linked-In Subscribe

Pro SharePoint 2007 Development  Pro SharePoint 2007 Records Management Development  6 Office Business Applications for SharePoint 2007

CAML.NET

SharePoint Evolutions 2010

SharePoint Job Tweets



SPDEVNET

Developer Resources

  • Fields WSS XSLT - Custom XSLT stylesheet that displays the default SharePoint column definitions in a table.
  • Custom Action Identifiers - A sortable table of default field definitions, including CAML declarations for writing content types.
  • CAML.NET Documentation - Online documentation for the CAML.NET class library.