Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

virtual server list

  Asked By: Pamela    Date: Mar 08    Category: Sharepoint    Views: 1254

I am trying to get the context in a Windows service to access a List of users..

following code works everywhere except in the Windows Service itself

SPGlobalAdmin globalAdmin = new SPGlobalAdmin();
SPSiteCollection siteCollections = globalAdmin.VirtualServers[0].Sites;
SPVirtualServer virtualServ=siteCollections.VirtualServer;
string ServerUrl = virtualServ.Url.ToString();
SPSite SiteCollection1 = new SPSite(ServerUrl);
SPWeb Site1 = SiteCollection1.OpenWeb();
return Site1;

Error i get is : Access in Denied
get this error at the second line in the code above.



1 Answer Found

Answer #1    Answered By: Upbrave C# expert     Answered On: Mar 08

This code  will only work for administrators. Using the SPGlobalAdmin
object requires Admin right. IF the user running in the context  code is
not a admin, you will need to impersonate the code

Didn't find what you were looking for? Find more on virtual server list Or get search suggestion and latest updates.