Best Practice
Expand Minimize

Best Practice

Rules to warn if best practices are not used.

Index

Rule Description Type Severity
SPC050101: Do not use spaces in file or folders names Files should be stored in subfolders which are named after the solution, or start with the solution. Avoid using dots or spaces in pathnames. Solution Warning
SPC050201: Instantiate a new SPSite inside RunWithElevatedPrivileges An SPSite object created outside the delegate can be referenced inside the delegate, however, the methods and property assessors of the object run with the privileges of the user context in which the objects were created, not with the elevated privileges. Assembly CriticalWarning
SPC050221: Do not call SPList.Items.Add Do not call SPList.Items.Add. Use SPList.AddItem instead. Assembly CriticalWarning
SPC050222: Do not call SPList.Items Do not call SPList.Items. Use SPList.GetItems(SPQuery query) instead. Assembly CriticalWarning
SPC050223: Do not call SPList.Items.GetItemById() Do not call SPList.Items.GetItemById(). Use SPList.GetItemById instead. Assembly CriticalWarning
SPC050224: Do not call SPList.Items[] Do not call SPList.Items[int] or SPList.Items[Guid]. Use SPList.GetItemByUniqueId(Guid) or SPList.GetItemById(int) instead. Assembly CriticalWarning
SPC050225: Do not call SPList.Items.Count Do not call SPList.Items.Count. Use SPList.ItemCount instead. Assembly CriticalWarning
SPC050226: Do not call SPListItemVersion.Delete to delete multiple versions When you delete multiple versions of a list item, use the DeleteByID() method; do not use the Delete() method. You will experience performance problems if you delete each SPListItemVersion object from an SPListItemVersionCollection object. Assembly CriticalWarning
SPC050227: Do not call SPFileVersion.Delete to delete multiple versions When you delete multiple versions of a file, use the DeleteByID() method; do not use the Delete() method. You will experience performance problems if you delete each SPFileVersion object from an SPFileVersionVersionCollection object. Assembly CriticalWarning
SPC050228: Do not enable ObjectTracking in Linq.DataContext If your code only queries lists, rather than adding, deleting, or editing list items, then you can turn off object change tracking. Doing so will improve performance. Set the ObjectTrackingEnabled property to false. Assembly Warning
SPC050229: Do not access SPListCollection by indexer multiple times Do not access SPListCollection by indexer multiple times. Instantiates the list object only once and assigns it to a variable in order to set properties and call methods. Assembly CriticalWarning
SPC050230: Do not call SPFolder.Files.Count Do not call SPFolder.Files.Count. Use SPFolder.ItemCount instead. Assembly CriticalWarning
SPC050231: Use SPBuiltInContentTypeId to reference builtin ContentType Use SPBuiltInContentTypeId to reference builtin ContentType. Assembly Warning
SPC050232: Use SPBuiltInFieldId to reference builtin Field Use SPBuiltInFieldId to reference builtin Field. Assembly Warning
SPC050233: Define RowLimit for SPQuery Define RowLimit for SPQuery to limit the number of items returned in the query. Assembly CriticalWarning
SPC050234: Avoid using AppSettings to store configuration values Avoid storing or reading configuration values in web.config via AppSettings. Assembly CriticalWarning
SPC050235: Apply lock when caching SharePoint objects Some SharePoint objects are not thread safe and caching can cause applications to fail and cause unexpected or unrelated user errors. To avoid this ensure locking of cached objects. Assembly CriticalWarning
SPC050236: Do not call SPItemEventProperties.OpenWeb() Do not call SPItemEventProperties.OpenWeb(). Use the newly introduced SPItemEventProperties.Web property instead for better performance and to avoid the need to call Dispose(). Assembly CriticalWarning
SPC050237: Do not request SPField from SPFieldCollection by index. Use SPFieldCollection.GetField() instead. Calling SPFieldCollection[] to retrieve a SPField in a web could fail if not the display name is used as argument. Better use SPWeb.Fields.GetField() which returns the field with the specified internal, display, or static name. Assembly CriticalWarning
SPC050238: Do not call SPWeb.GetListFromUrl. Use SPWeb.GetListFromWebPartPageUrl instead. SPWeb.GetListFromUrl gets the list that is associated with the first Web Part on the specified Web Parts page. Beginning in Windows SharePoint Services 3.0, use the GetListFromWebPartPageUrl method instead of this method. Assembly CriticalWarning
SPC050239: Do not call PublishingWeb.GetPublishingPages() Do not call PublishingWeb.GetPublishingPages(). Use PublishingWeb.GetPublishingPages(SPQuery query) or PublishingWeb.GetPublishingPages(uint rowLimit) instead to improve performance and limit the number of returned pages. Note: PublishingWeb.GetPublishingPages() does not return pages inside subfolders. Use then PublishingWeb.GetPublishingPages(SPQuery query) instead. Assembly CriticalWarning
SPC050250: Assign RowLimit for SPQuery in limited range Assign RowLimit for SPQuery within the limited range (default 1 to 2000). Assembly CriticalWarning
SPC050251: Use SPMonitoredScope with Developer Dashboard, on all custom code When enabling developer dashboard feature in SharePoint 2010, in order to get all of the custom code included in the developer dashboard output, wrap it in a monitored scope. Assembly CriticalWarning
SPC050252: Timer jobs instances should be created in a Feature Activated When creating a new Timer Job instance, ensure that it is created in the FeatureActivated method of a Feature Receiver. Assembly CriticalWarning
SPC050253: Use SPMonitoredScope with Developer Dashboard, on all custom code When enabling developer dashboard feature in SharePoint 2010, in order to get all of the custom code included in the developer dashboard output, wrap it in a monitored scope. Assembly CriticalWarning
SPC052101: Do not activate or deactivate Features via API Do not activate or deactivate Features in code via API. Consider using PowerShell or Feature Stapling. Assembly CriticalWarning
SPC052201: Custom field types should not be user creatable Custom field types should not be user creatable because in this case they are visible in the complete farm which may not be the intention. FieldType Warning
SPC055101: Attribute 'Name' and 'StaticName' should have the same value in Field The value of attribute 'Name' and 'StaticName' should be the same in a Field. Otherwise it might lead to confusion when requesting the field via REST, in managed code etc. Field CriticalWarning
SPC055102: Consider setting attibute 'AllowDeletion' to FALSE in Field to prevent deletion by users Setting the attribute 'AllowDeletion' to FALSE prevents unintended deletion of a Field by the user or administrator. Field Information
SPC055201: Consider using SPContentTypeCollection.BestMatch(SPContentTypeId) to retrieve a Content Type Use SPContentTypeCollection.BestMatch(string) to retrieve a Content Type from a SPContentTypeCollection. Assembly CriticalWarning
SPC055202: Consider setting attibute 'Sealed' to TRUE in ContentType to prevent changes by users Setting the attribute 'Sealed' to TRUE prevents unintended changes of a ContentType by the user or administrator. ContentType Information
SPC055501: Define Type of ListTemplate greater than 10000 The ListTemplate Type should be greater than 10000. This makes it easier to identify custom ListTemplates. ListTemplate CriticalWarning
SPC055502: Add ContentType for folders to ListTemplate A custom ListTemplate should contain the folder ContentType to work properly. ListTemplate CriticalWarning
SPC055503: Avoid definition of ContentTypes in ListTemplates. ContentTypes which are defined in a ListTemplate are not re-usable. Better define the ContentType separately and reference the ContentType in the ListTemplate. ListTemplate CriticalWarning
SPC055504: Consider setting attibute 'AllowDeletion' to FALSE in ListTemplate to prevent deletion by users Setting the attribute 'AllowDeletion' to FALSE prevents unintended deletion of a ListTemplate by the user or administrator. ListTemplate Information
SPC056001: Do not instantiate SPList in Receiver Do not instantiate an SPList object within an event receiver. Assembly Warning
SPC056002: Do not instantiate SPListItem in Receiver Do not instantiate an SPListItem object within an event receiver. Assembly Warning
SPC056003: Do not instantiate SPSite in Receiver Do not instantiate an SPSite object within an event receiver. Assembly Warning
SPC056004: Do not instantiate SPWeb in Receiver Do not instantiate an SPWeb object within an event receiver. Assembly Warning
SPC056401: Declare property 'AllowClose' in WebPart to prevent closing of webpart by the user A WebPart should contain the attribute 'AllowClose' with value False to prevent that users close the webpart. In this case the webpart would be disappear from the UI but will remain inside the page. WebPart CriticalWarning
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.