Search code examples
wcfiisiis-7virtual-directory

Accessing a IIS virtual directory via a WCF service


I'm running a WCF service and in order to access a directory on the machine I'm running the WCF service in ASP.Net compatibility mode.

For security reasons I've set the directory up as a virtual directory but I've no idea how to access it to retrieve a file.

As a test to see if I can access the directory I've tried (where "CubeDocs" is the virtual dir):

 System.IO.Directory.GetFiles(HostingEnvironment.MapPath("CubeDocs"))

But this returns "The relative virtual path 'CubeDocs' is not allowed here."

What should I be doing?


Solution

  • You need to use Server.MapPath, like so:

    string path = HttpContext.Current.Server.MapPath("CubDocs");