Best Practices

Best Practices

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. AssemblyFileReference CriticalWarning
SPC050222: Do not call SPList.Items Do not call SPList.Items. Use SPList.GetItems(SPQuery query) instead. AssemblyFileReference CriticalWarning
SPC050223: Do not call SPList.Items.GetItemById() Do not call SPList.Items.GetItemById(). Use SPList.GetItemById instead. AssemblyFileReference 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. AssemblyFileReference CriticalWarning
SPC050225: Do not call SPList.Items.Count Do not call SPList.Items.Count. Use SPList.ItemCount instead. AssemblyFileReference 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. AssemblyFileReference 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. AssemblyFileReference 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. AssemblyFileReference 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. AssemblyFileReference CriticalWarning
SPC050230: Do not call SPFolder.Files.Count Do not call SPFolder.Files.Count. Use SPFolder.ItemCount instead. AssemblyFileReference CriticalWarning
SPC050231: Use SPBuiltInContentTypeId to reference builtin ContentType Use SPBuiltInContentTypeId to reference builtin ContentType. AssemblyFileReference Warning
SPC050232: Use SPBuiltInFieldId to reference builtin Field Use SPBuiltInFieldId to reference builtin Field. AssemblyFileReference Warning
SPC050233: Define RowLimit for SPQuery Define RowLimit for SPQuery to limit the number of items returned in the query. AssemblyFileReference CriticalWarning
SPC050234: Avoid using AppSettings to store configuration values Avoid storing or reading configuration values in web.config via AppSettings. AssemblyFileReference 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. AssemblyFileReference 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(). AssemblyFileReference 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. AssemblyFileReference 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. AssemblyFileReference CriticalWarning
SPC050250: Assign RowLimit for SPQuery in limited range Assign RowLimit for SPQuery within the limited range (default 1 to 2000). AssemblyFileReference 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. AssemblyFileReference 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
SPC055201: Consider using SPContentTypeCollection.BestMatch(SPContentTypeId) to retrieve a Content Type Use SPContentTypeCollection.BestMatch(string) to retrieve a Content Type from a SPContentTypeCollection. AssemblyFileReference CriticalWarning
SPC055501: Define Type of ListTemplate greater than 10000 The ListTemplate Type should be greater than 10000. This makes it easier to identify custom ListTemplates. ListTemplateDefinition CriticalWarning
SPC056001: Do not instantiate SPList in Receiver Do not instantiate an SPList object within an event receiver. AssemblyFileReference Warning
SPC056002: Do not instantiate SPListItem in Receiver Do not instantiate an SPListItem object within an event receiver. AssemblyFileReference Warning
SPC056003: Do not instantiate SPSite in Receiver Do not instantiate an SPSite object within an event receiver. AssemblyFileReference Warning
SPC056004: Do not instantiate SPWeb in Receiver Do not instantiate an SPWeb object within an event receiver. AssemblyFileReference Warning
comments powered by Disqus