Thursday, June 11, 2015

WCF: How to get application physical base directory

I am generating a temp file in my WCF and wanted to store in a Temp folder inside my WCF.

HTTPContext does not apply for WCF, so we can't use that to get the base directory

Environment.CurrentDirectory => Will provide you the debug/bin directory

AppDomain.CurrentDomain.BaseDirectory => Will provide you the debug/bin directory as well.

System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath => Will provide you the Application base directory.

Note that, System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath will work only if you host the WCF Service as Web application..

If you host the WCF Service from console, it will always return null.

No comments:

Post a Comment