0

I have a SharePoint site collection. The root Web of the site collection has the URL http://intranet.com. 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("http://intranet.com");

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? :(

1 Answer 1

3

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;
1
  • Thanks, after your reply, I tried to use SPSite currentSite = SPContext.Current.Site; which is also working fine!!
    – NICK
    Commented Jun 11, 2012 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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