SPC050231: Use SPBuiltInContentTypeId to reference builtin ContentType

Use SPBuiltInContentTypeId to reference builtin ContentType.

TypeName: UseBuiltInContentTypesInsteadOfStrings
CheckId: SPC050231
Severity: Warning
Type: AssemblyFileReference
Resolution

Replace strings which contain the ID of a SharePoint default ContentType with the SPBuiltInContentTypeId.

Bad Practice:

// retrieve Document ContentType by string
SPContentTypeId documentCTypeId = new SPContentTypeId("0x0101");
SPContentType documentContentType = web.AvailableContentTypes[documentCTypeId];
Good Practice:
// retrieve Document ContentType by SPBuiltInContentTypeId class
SPContentType documentContentType = web.AvailableContentTypes[SPBuiltInContentTypeId.Document];

Links

comments powered by Disqus