SPFieldLookup Property LookupWebId Update Security

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hello,

I am trying to create a list which has a lookup field to refer to the
root
site list.
With RunWithElevatedPrivileges, it does not allow.
Please help me.
Kenny.


Guid rootWebId = spSite.RootWeb.ID;

// Product in Service Logs

SPList spListServiceLogs = subWeb.Lists["Service Logs"];


SPSecurity.RunWithElevatedPrivileges(
delegate()
{

SPFieldLookup spProductFieldLookup =
(SPFieldLookup)spListServiceLogs.Fields["Product"];
spProductFieldLookup.LookupList =
spWeb.Lists["Products"].ID.ToString();

spProductFieldLookup.LookupWebId = rootWebId;
spProductFieldLookup.Update();

});


[System.UnauthorizedAccessException] {"Access is denied. (Exception
from
HRESULT: 0x80070005
(E_ACCESSDENIED))"} System.UnauthorizedAccessException

<StackTrace>
at
Microsoft.SharePoint.SPGlobal.HandleUnauthorizedAccessException(UnauthorizedAccessException
ex)\r\n
at Microsoft.SharePoint.Library.SPRequest.GetAllWebsOfSite(String
bstrUrl,
Object& pvarWebs, Object& pvarWebIds, Object& pvarParentWebs, Object&
pvarLangs, Object& pvarTitles)\r\n
at
Microsoft.SharePoint.SPSite.SPWebCollectionProvider.GetWebsData(String[]&

strNames, String[]& strServiceRelUrls, Guid[]& guidWebIds, Int32[]&
nLanguages, String[]& strTitles, String[]& strDescriptions, String[]&
strCreationTimes, String[]& strModifiedTimes, Boolean[]&
bUserIsWebAdmins,
Int32[]& nWebTemplates, Int16[]& nProvisionConfigs, Int16[]&
nMeetingCounts)\r\n
at Microsoft.SharePoint.SPWebCollection.EnsureWebsData()\r\n at
Microsoft.SharePoint.SPWebCollection.get_Item(Guid id)\r\n
at Microsoft.SharePoint.SPFieldLookup.set_LookupWebId(Guid value)\r\n

at
Microsoft.SharePoint.Office.WebControls.CreateProjectButton.<>c__DisplayClass1.<updateGlobalLookupField>b__0()

in C:\\SharePoint\\CreateProjectButton.cs:line 188

.


Quantcast