Question

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.

Was it helpful?

Solution

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 :)

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top