http://labs.episerver.com/en/Blogs/Ruwen/Dates/111218/111219/111222/
There is also a BypassAccessCheck property on UnifiedDirectory.
WebRequest request = HttpWebRequest.Create(new Uri(HttpContext.Current.Request.Url, Request.QueryString["url"]));
WebResponse response = request.GetResponse();
Now I have also tried to enable EPiServer's basic authentication module and disable anonymous access. When I access the file directly (on the address "url" above) I get the login screen from the browser and after logging in I can access the file. Then I would assumes that the code lines above would also be able to access the file if in between I add this:
request.Credentials = new NetworkCredential("admin", "Password");
However, that also does not work. I am running out of ideas now...
Not sure if I've understood what your needs are, but this is how i fetch a file from a virtual path provider in CMS 5.
VirtualFile file = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile( CurrentPage[”FilePath”].ToString() );
UnifiedFile f = file as UnifiedFile;
Hope it might be some help.