Index

SPWebPartManager is used while HTTPContext is null

SharePoint supports a custom implementation of WebPartManager named SPWebPartManager. In addition, there is an SPLimitedWebPartManager class that supports environments that have no HttpContext or Page available.

Static SP-object used as field

Avoid having SPite, SPWeb, SPList, SPFile, SPFolder, SPListItem as static field inside classes.

Thread.Sleep() usage

Avoid using Thread.Sleep() within SharePoint solutions.

Unsafe cast on SPItemEventDataCollection.Item

While using SPItemEventProperties the SPItemEventDataCollection.Item contains data for specified key. In case of key missing it returns null so null reference exceptions might be arised with ToString() call.

Unsafe cast on SPListItem

SPListItem is untyped entity, so null reference exceptions on nullable types or wrong type conversion exception might arise.

Unsafe SPObject.Name == <string> comparison

Depending on the case, SPObject.Name string based comparison is quite unsafe and might lead to the potential issues. In case of loop the result is performance degradation.

Unsafe url concatenation

Url property for SPSite, SPWeb and SPFolder may return string with or without trailing slash.

Use FeatureIds class

SharePoint provides some classes containing the out of the box ID’s, you only have to know they exist. The FeatureIds class contains 16 GUID’s for the MOSS publishing features. You can find them all on the FeatureIds fields page.

Use FieldId class

SharePoint provides some classes containing the out of the box ID’s, you only have to know they exist. The FieldId class contains 61 GUID’s for the publishing fields. You can find them all on the FieldId properties page

Use PropertyConstants class

SharePoint provides some classes containing the out of the box names, you only have to know they exist. The PropertyConstants class contains 106 constants for the default SharePoint user profile propertiess. You can find them all on the PropertyConstants fields page.

Use SPBuiltInFieldId class

SharePoint provides some classes containing the out of the box ID’s, you only have to know they exist. The SPBuiltInFieldId class contains 314 GUID’s for the default SharePoint fields. You can find them all on the SPBuiltInFieldId fields page.

Use try-catch for SPFile.Exists

Although it may seem intuitive that accessing the SPFile.Exists property would return True or False, in fact, if a file doesn’t exist, it throws an ArgumentException error.

UserProfileManager.GetEnumerator() is used

UserProfileManager.GetEnumerator() should not be used.

UTC time is used

SharePoint web site (SPWeb) has it own regional settings with time zone, independent from Windows. You need to consider site regional settings in all datetime conversion procedures.

Login