I had a request from a client today to save something uploaded through WCF to the local disk to a particular sub folder.

Normally this is easy in ASP.NET with Server.MapPath but this isn’t available in the WCF application.

You can get the path of the application hosting the WCF service using:

var physicalPath = AppDomain.CurrentDomain.BaseDirectory

To get a virtual path you can use:

VirtualPathExtension extension = OperationContext.Current.Host.Extensions.Find<VirtualPathExtension>();
var virtualPath = extension.VirtualPath;

1 Comment