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 curren
You can use
AppDomain.CurrentDomain.BaseDirectory;
This gives you the root directory of your application.
Best way is using
HostingEnvironment.ApplicationPhysicalPath
under System.Web.Hosting
for more information please refer this link
HttpContext.Current.Server.MapPath("..") [observe two(..) dots instead of (.)] gives physical directory of Virtual Directory of the site!
HttpContext.Current.Server.MapPath("~/") maps back to the root of the application or virtual directory.
HttpContext.Current.Server.MapPath("~/") <-- ROOT
HttpContext.Current.Server.MapPath(".") <-- CURRENT DIRECTORY
HttpContext.Current.Server.MapPath("..") <-- PARENT DIRECTORY
All the above is relative, so you can you any combination to traverse the directory tree.
HttpContext.Current.Server.MapPath(".")
will give you the current working directory.
But to Rohan West's comment about potentially being outside of an HttpContext it would probably be better to just call:
HostingEnvironment.MapPath(".")
See details here
In a webservice, you are running in a http context. So,
HttpContext.Current.Server.MapPath("~/")
will give you the answer.