From: kenny on
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

From: Engelbert on
Please post WSS programming questions to the subnewsgroup that was created
for them and where the programming experts are (if they haven't already
moved to the alternative which is the new newsgroup
microsoft.public.sharepoint.development_and_programming)

microsoft.public.sharepoint.windowsservices.development

Engelbert

"kenny" <kkimusa(a)msn.com> wrote in message
news:1161726473.811263.48060(a)m7g2000cwm.googlegroups.com...
> 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
>