开发者

SharePoint: Common mistakes [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guida开发者_开发知识库nce. Closed 11 years ago.

Recently I figured out one terrible thing I was not supposed to do when doing SharePoint development:

using (var spSite = SPContext.Current.Site)
{
    // do something
}

After some hair pulling I figured out that the code above was actually disposing my current SharePoint context.

This urges me to question if there are any other such common mistakes that I or any other SharePoint developer should not be making?


  1. Not disposing SPSite & SPWeb objects you "new" up in your code.
  2. Disposing Context.SPSite & SPWeb objects
  3. Disposing SPWeb.ParentWeb objects (this is done for you)

See Best Practices: Using Disposable Windows SharePoint Objects

  1. Not using Output Cache with Publishing sites
  2. Not using WSP solutions to deploy custom code changes.


For checking your code against these kind of mistakes (What to dispose and what not to), I would suggest using SPDisposeChecker.

http://archive.msdn.microsoft.com/SPDisposeCheck

Also, you can read article by Roger Lamb (on which this tool is based on) for understanding more about this:

http://blogs.msdn.com/b/rogerla/archive/2008/02/12/sharepoint-2007-and-wss-3-0-dispose-patterns-by-example.aspx

Hope it helps.

DG

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜