Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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
add comment

Your Answer

 
discard

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.