SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 2 down vote accepted

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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