Enums, Constants, and other good stuff in the SharePoint API

Sometimes you need to access stuff in SharePoint by id or internal name. Or maybe you to compare something with a constant MOSS value. Or maybe you need to…well you get the point, don´t you?

These are some examples that I have used in my adventures together with MOSS/SharePoint. Hope you find them useful.


SPListTemplateType

SPWeb.GetCatalog will find an instance of SPList. (in this case _catalogs/masterpage).

SPList list = pubSite.RootWeb.GetCatalog(SPListTemplateType.MasterPageCatalog);

SPBuiltInContentTypeId

Sometimes you need to have access to the ContentType Ids from WSS.

if(list.ContentTypes[SPBuiltInContentTypeId.Item] != null)

ContentTypeId

same as above but together with the MOSS specific ContentTypes Ids.

PublishingPage aspx = GetPage();
if (aspx.Layout.AssociatedContentType.Id == ContentTypeId.Page)
{

}

FeatureIds

If you need to access the Ids of features (ex FeatureIds.Publishing).


SPBuiltInFieldId

Accessing properties on your SPListItem by id.

SPListItem item = GetItem();
item[SPBuiltInFieldId.Title] = "My new title";

FieldId

Same as above but for things in MOSS (publishing)

 SPListItem item = GetItem();
 item[FieldId.AudienceTargeting] = "[guid for the audience]";
 

Enjoy

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: