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.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trackbacks and Pingbacks: