You need to prevent the error from occurring

You have a SharePoint site collection. The root Web of the site collection has the URL
http://intranet. You plan to create a sandboxed solution that will contain a Web Part. The Web Part
will display the title of the root Web. You write the following code segment for the Web Part. (Line
numbers are included for reference only.) 01 SPSite currentSite = new SPSite(“http://intranet”); 02
03 Label currentTitle = new Label(); 04 currentTitle.Text = currentSite.RootWeb.Title; You add 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.” You need to prevent the error from
occurring. What should you do?

You have a SharePoint site collection. The root Web of the site collection has the URL
http://intranet. You plan to create a sandboxed solution that will contain a Web Part. The Web Part
will display the title of the root Web. You write the following code segment for the Web Part. (Line
numbers are included for reference only.) 01 SPSite currentSite = new SPSite(“http://intranet”); 02
03 Label currentTitle = new Label(); 04 currentTitle.Text = currentSite.RootWeb.Title; You add 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.” You need to prevent the error from
occurring. What should you do?

A.
Add the following line of code at line 02: currentSite.OpenWeb();

B.
Add the following line of code at line 02: currentSite.OpenWeb(“http://intranet”);

C.
Change line 01 to the following code segment: SPSite currentSite = SPContext.Current.Site;

D.
Change line 04 to the following code segment: currentTitle.Text = currentSite.OpenWeb().Title;



Leave a Reply 0

Your email address will not be published. Required fields are marked *