Sunday, March 17, 2013

Do's and Don't's in SharePoint Programming (draft)
 
 
 1. Use SPWeb.Lists.TryGetLists("ListName")



SPList list = web.Lists.TryGetList("List Name");
if (list != null)
{
     ...
}

Don't use SPWeb.Lists["ListName"] which will throw exception when list with the name doens't exists.

2. Don't dispose your current context!
 
Don't do this

using (SPContext.Current.Web)
{
    ...
}
 
or
 
SPWeb web = SPContext.Current.Web;
using (web)
{
    ...
}
 
Otherwise you will see errors.


3. Always use _spBodyOnLoadFunctionNames and ExecuteOrDelayUntilScriptLoaded together and avoid using jQuery $(document).ready(function() {...}); or JavaScript windows.load = function() { ...};

        if (ExecuteOrDelayUntilScriptLoaded && _spBodyOnLoadFunctionNames) {
            _spBodyOnLoadFunctionNames.push(ExecuteOrDelayUntilScriptLoaded(initSaveMenu, "sp.js"));
        }




 
 

No comments:

Post a Comment