How do I get the current directory in a web service

前端 未结 7 809
情歌与酒
情歌与酒 2020-12-09 08:04

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

相关标签:
7条回答
  • 2020-12-09 08:18

    You can use

    AppDomain.CurrentDomain.BaseDirectory;
    

    This gives you the root directory of your application.

    0 讨论(0)
  • 2020-12-09 08:22

    Best way is using

    HostingEnvironment.ApplicationPhysicalPath under System.Web.Hosting

    for more information please refer this link

    0 讨论(0)
  • 2020-12-09 08:31

    HttpContext.Current.Server.MapPath("..") [observe two(..) dots instead of (.)] gives physical directory of Virtual Directory of the site!

    0 讨论(0)
  • 2020-12-09 08:34

    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.

    0 讨论(0)
  • 2020-12-09 08:35

    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

    0 讨论(0)
  • 2020-12-09 08:42

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

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

    will give you the answer.

    0 讨论(0)
提交回复
热议问题