English 中文(简体)
Detecting custom folder content types in MOSS2007
原标题:

Given an SPListItem representing a folder, I need to find out whether it has the builtin folder content type, or a custom folder content type (with additional fields).

Here is what I do

    SPContentType folderType = aFolderItem.Web.AvailableContentTypes[SPBuiltInContentTypeId.Folder];
    SPContentType contentType = aFolderItem.ContentType;

    if ( contentType != folderType )
       ...

However, for default folders I still get a different content type than the built in type. They have IDs like 0x0120007C34D9760794FA43AB267F4E1A1BF460 . I m not sure where this particular GUID suffix comes from, I can t find it in any of the definition of my features folder.

My best guess is that instantiated folders always get a custom type. If that s the case, any suggestion on how I might be able to differentiate between builtin folders and custom folders?

最佳回答

If a content type is attached to a list, then it will not be attached directly but a copy of it will be created and attached. The original content type id is then annexed with a Guid and becomes the "new" content type s id.

If you kept to the guide lines for defining content type ids, then you custom folder content type id should look something like 0x0120 + 00 + <Guid>.

So if you check an item s content type whether it is a default or a custom folder, the id of a custom folder will look something like 0x0120 + 00 + <Guid> ==> Base folder content type id + a Guid for attaching it to a list.

In contrast to that the id of a custom folder will look something like 0x0120 + 00 + <Guid> + <Guid> ==> Base folder content type + a Guid for your custom content type + a Guid for attaching it to a list.

To make the comparison a little bit easier you should not compare the actual content type s id but have a look at the content type id s parent id. For a custom folder the parents id is 0x0120, for a custom folder it will be 0x0120 + 00 + <Guid>.

问题回答

Assuming that aFolderItem is the Variable of type SPListItem below code should get what you want.

if(aFolderItem.ContentType.Id.IsChildOf(SPBuiltInContentTypeId.Folder))
          ...this is a Folder
else
          ...this is not a Folder




相关问题
SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

UI automated testing within SharePoint

I m looking for automated Functional Testing tools that can manipulate SharePoint sites, libraries, and documents thought the web interface. It needs to be extensible enough to handle any custom ...

Enable authorization on sitemap provider

I want to enable Authorization on the Site map provider. We have enabled anonymous access to the site and we want the Site map provider to be visible only to authorized users. I tried ...

SharePoint : web service permission error

I have a sharepoint site, and I am calling a standard sharepoint web service. I create the web service request like this : wsDws.Url = this.SiteAddress + @"/_vti_bin/Dws.asmx"; When I use ...

Sharepoint 2007 Data view Webpart custom parameters

I m sort of new to the custom parameters that can be setup on a DataView Webpart. There are 6 options: - None - Control - Cookie - Form - QueryString - Server Variable I think that None, Cookie and ...

热门标签