Index

Magic string is used

Avoid hardcoded urls, emails, accounts in code.

Missing SPUrlZone param in SPSite constructor

The SharePoint object model always creates new SPSite objects with the zone set to Default, even if the code that’s creating the object is running under a SharePoint extended web application associated with a zone other than Default.

Not logged exception found

Catch block should include ULS logging output or re-throw.

PortalLog is used

This class and its members are reserved for internal use and are not intended to be used in your code.

RunWithElevatedPrivileges is used while HTTPContext is null

You do not have elevation of privilege when using SPSecurity.RunWithElevatedPrivileges in (1) Workflow, (2) Timer Job, (3) Feature Receiver or (4) Event handler (SPItemEventReceiver, SPListEventReceiver,SPWebEventReceiver, SPWorkflowEventReceiver) in the follow cases:

SPContext objects are disposed

SPContext objects are managed by the SharePoint framework and should not be explicitly disposed in your code.

SPContext.Current is used outside web context

Avoid using SPContext.Current outside of web request context.

SPDataSource.Scope is missed

How do we know what people want – folder, inside folder, or just items? SPQuery has an "affected scope"...

SPFeature activated via code

Avoid feature activation via code. It leads to “black boxed” feature activation chain, which leads to pooor overall solution quality, traceability and supportability.

SPListItem.File is used

For non document library it returns null.

SPMonitoredScope should be used

It might be good to use SPMonitoredScope construction in visual components code, hence it might use with together developer dashboard.

SPPersistedObject is updated

SharePoint 2010+ has security feature to all objects inheriting from SPPersistedObject. This feature explicitly disallows modification of SPPersistedObject objects from content web applications (not CA).

SPQuery.Scope is missed

How do we know what people want – folder, inside folder, or just items? SPQuery has an “affected scope”.

SPUtility.SendEmail usage while SPContext is null

Sending an e-mail from a WCF service when SPContext is not available could fail. As a workaround, you have to prevent the mail function from reading the current context by using HttpContext.Current = null. If it can’t, it will retrieve the right context and it will then work.

SPView.Scope is missed

How do we know what people want – folder, inside folder, or just items? SPView has an "affected scope".

Login