Tag Archives: ApplicationPhysicalPath

WCF service local path

Developing that small WCF presentation that I was talking about earlier, I got stumped on trying to get the local path. The server needs to access the App_Data folder to handle uploads and downloads but it needs the base path for that.

No, you don’t get HttpContext (HttpContext.Current is null) although the service is bound over basicHttpBinding.

Luckily I’ve found via StackOverflow that there is HostingEnvironment.ApplicationPhysicalPath which will help you.

Therefore a simple

public class Service : IService
{
    private readonly string _dataFolder;

    public Service()
    {
       _dataFolder = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "App_Data");
    }
}

.. will suffice.