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 a SharePoint site collection. The root Web of the site collection has the URL I plan to create a user solution that will contain a Web Part. The Web Part will display the title of the root Web.

I wrote the following code segment for the Web Part.

SPSite currentSite = new SPSite("");

Label currentTitle = new Label();

currentTitle.Text = currentSite.RootWeb.Title;

I added the Web Part to a page in the root Web and receive the following error message: "Web Part Error:Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred."

What should I do? :(

share|improve this question
up vote 3 down vote accepted

In a sandboxed solution you can only access the current site collection, not one specified by URL.

To get the title of the RootWeb of the current site collection use:

currentTitle.Text = SPContext.Current.Site.RootWeb.Title;
share|improve this answer
Thanks, after your reply, I tried to use SPSite currentSite = SPContext.Current.Site; which is also working fine!! – NICK Jun 11 '12 at 11:15

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.