Sunday, March 4, 2012

Trouble 1: Trying to use an SPWeb object that has been closed or disposed and is no longer valid


This code is error

Private void GetData()
{
    using (SPWeb ospWeb = SPContext.Current.Web)
     {
           //code here
     }
}

Replace code  here

Private void GetData()
{
     using(SPSite spSite=new SPSite(SPContext.Current.Web.Url))
     {
          using (SPWeb spWeb = spSite.OpenWeb())
            {
              //code here
            }
    }
}

1 comment:

  1. Thanks Dear,


    Your Code is very helpfull.i am biggner in sharepoint.Can you give me your mailid.


    Gopal chauhan
    gopal.chanhan@gmail.com

    ReplyDelete