Search This Blog

Thursday, February 12, 2015

What is difference between SPContext.Current.Web and SPContext.Current.Site.OpenWeb()

 

To refer SPWeb object sometimes we use SPContext.Current.Web or SPContext.Current.Site.OpenWeb(). Here we will see What are differences between SPContext.Current.Web and SPContext.Current.Site.OpenWeb()
SPContext.Current.Site.OpenWeb()
  1. Creates a new instance of the SPWeb object, and we are responsible to dispose after using it.
  2. OpenWeb() with out sending parameters opens root web of current site collection. If OpenWeb() with parameters opens specific web site.
  3. Expensive call - It cost more resources than reusing an existing one.
SPContext.Current.Web :
  1. Gives you access to the current instance of SPWeb, and you must not dispose it
  2. Gives current Subsite if you are at web other than root web.



No comments:

Post a Comment