0

I have the following URL to a subsite : http://myServerName/subSiteName I know the URL to the subsite upfront.

So far I'm trying this, but it won't work.

using (SPSite spSite = new SPSite(this.siteURL))
{
  using (SPWeb spWeb = spSite.OpenWeb(this.siteURL))
    {

    }
}

Any ideas why not? And what I'm doing wrong?

SPSite loads fine, but not SPWeb.

2

That's it :) Works event with List-URLs to open a list (remove the "/AllItems.aspx")!

BTW: You don't have to Dispose SPWeb as long as you Dispose the SPSite object it came from. So in your case

using (SPSite spSite = new SPSite(this.siteURL))
{
  SPWeb spWeb = spSite.OpenWeb();
  SPList list = spWeb.GetList(this.siteURL);
  [...]
}

...would be fine :)

1

This is actually easier to solve than I thought it would be.

using (SPWeb spWeb = spSite.OpenWeb())

This opens the URL of the site in the SPSite constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.