views:

1696

answers:

3

Hi

I am using System.IO.Directory.GetCurrentDirectory() to get the current directory in my web service, but that does not give me the current directory. How do I get the current directory in a web service?

Thanks Stuart

+7  A: 

In a webservice, you are running in a http context. So,

HttpContext.Current.Server.MapPath("~/")

will give you the answer.

driis
A: 

HttpContext.Current.Server.MapPath("~/") would get you the root of the application?

Which is plenty most likely as you probably know the path from there.

A difference which might be of interest

HttpContext.Current.Server.MapPath("/Directory/") builds from the root of the application no matter what

HttpContext.Current.Server.MapPath("Directory/") without the first slash this will take directory from where you call as the start.

dove
A: 

I believe HttpContext.Current.Server.MapPath(".") will give you the current working directory

felickz