Unable to Access a folder with code.

Vote:
 

I am trying to access a VPP folder through Job-Subscription.

This folder do not have EVERYONE access rights defined in FileManagement, and as Job-Scheduler needs Everyone access to explore this folder through code it fails. and gives error as "Dont have sufficient access to this folder".

UnifiedDirectory dir = HostingEnvironment.VirtualPathProvider.GetDirectory(VirtualPath) as UnifiedDirectory;

How will you give BYPASSACCESSCHECK to a Unifieddirectory as the above statement gives error.

#32641
Sep 10, 2009 18:31
Vote:
 

An alternative solution could be to impersonate a user with sufficient permissions in the scheduled job,

/johan

 

#32642
Sep 10, 2009 20:54
Vote:
 

Hi Nitin.

You can get the UnifedDirectory by giving bypass access check this way:

UnifiedDirectory dir = EPiServer.Web.Hosting.VirtualPathHandler.Instance.GetDirectory("virtualPath", true) as UnifiedDirectory; 
if(dir != null) 
{
// Do your stuff
}

But the best way is probably to impersonate as Johan says. Look at Erik Nordin`s blog for a great example on impersonation in a scheduled job. http://antecknat.se/blog/2009/03/04/scheduled-tasks-tips/ 

Hope this helps!

Br, Tore

#32648
Sep 11, 2009 8:45
Vote:
 
Thanks a lot for the replies
#32756
Sep 16, 2009 13:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.