PrepAway - Latest Free Exam Questions & Answers

What should you do?

You create a Web Part that programmatically updates the description of the current SharePoint site.

The Web Part contains the following code segment. (Line numbers are included for reference only.)

01 SPSecurity.RunWithElevatedPrivileges(delegate()
02 {
03 SPSite currSite = SPContext.Current.Site;
04 SPWeb currWeb = SPContext.Current.Web;
05 using (SPSite eSite = new SPSite(currSite.ID))
06 {
07 using (SPWeb eWeb = eSite.OpenWeb(currWeb.ID))
08 {
09 eWeb.AllowUnsafeUpdates = true;
10 currWeb.Description = “Test”;
11 currWeb.Update();
12 eWeb.AllowUnsafeUpdates = false;
13 }
14 }
15 });

Users report that they receive an Access Denied error message when they use the Web Part. You need to ensure that all users can use the Web Part to update the description of the current site.

What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Remove lines 09 and 12.

B.
Remove lines 10 and 11.

C.
Change lines 10 and 11 to use the eWeb variable.

D.
Change lines 09 and 12 to use the currWeb variable.

Explanation:
MNEMONIC RULE: “eWeb”

The inner using statement works with eWeb object, so we should use eWeb object all along.


Leave a Reply