Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0×80030102(STG_E_REVERTED))


In my web part I used followig code
I used to write the code like this
using (SPSite _site = SPContext.Current.Site)
{
  using (SPWeb _web = site.RootWeb)
  {
   // your code
  }
}
To correct this issue use code like following in my web part

SPSite currSite = SPContext.Current.Site;
SPWeb currWeb = currSite.RootWeb;
using (SPSite eSite = new SPSite(currSite.ID))
{
 using (SPWeb eWeb = eSite.OpenWeb(currWeb.ID))
 {
    //Your code
 }
}
Happy coding…

Comments

Popular posts from this blog

How to get SPUser or SPGroup from Person or Group field

SharePoint publishing page scheduling

Adding new font into Rich Text Editor font DropDown box in SP 2010