- Avoid empty catch blocks and use error logging instead.
- Use the ‘as’ operator to cast reference types instead of a type cast. This saves you a NullReferenceException in case of an invalid cast.
- Use the TryParse methods to convert strings to value types instead of the Convert class.
- Everything placed in a 12-hive sub folder should have it’s custom folder (such as Application name) – except for the Xml folder.
- Avoid Access Denied errors using the SPWeb.GetSubWebsForCurrentUser() instead of SPWeb.Webs property.
- Use the SPSite.OpenWeb(string, bool) overload to open a site from user input or check the Url property of SPWeb after opening. Otherwise you cannot be sure that you have opened the correct site.
- Use Uri and UriBuilder class to work with URL whenever possible.
- Use SPUrlUtility to work with url’s. It has methods to combine urls and more.
- Never use the SPList.GetItemById. This performs really badly on bigger lists. Either use a SPQuery or the cached methods of the PortalSiteMapProvider.
- Check list existence prior to using it. Requires a foreach over the Web’s SPListCollection (remember to break when found). Consider to use the ListsForCurrentUser property.
- Avoid duplicating logic… Create code libraries with general methods and classes, instead of having the same method/logic in multiple classes/projects.
- Use try/catch statements when reading/writing from ressources, and handle them gracefully instead of throwing them to end users.
- Use stringbuilder to concatenate strings.
- Proper use of Dispose() on disposable sharepoint objects as SPWeb and SPSite.
- Use the buildin functionality in Visual Studio to format documents (CTRL+K, CTRL+D)
- When writing and reading to/from a SharePoint List, create a DAL for doing these operations.
- Use variables (constants) and refer to these, when using strings in the code.
Posts Tagged ‘WSS’
Some tips for MOSS or WSS developer
2009年06月10日 星期三