最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#獲取根目錄實(shí)現(xiàn)方法匯總

 更新時(shí)間:2020年09月24日 09:23:30   作者:撈月亮的猴子  
這篇文章主要介紹了C#獲取根目錄實(shí)現(xiàn)方法匯總,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

1.控制臺(tái)應(yīng)用程序

static void Main(string[] args)
    {
      //1.Environment.CurrentDirectory
      Console.WriteLine(Environment.CurrentDirectory);
      //2.AppDomain.CurrentDomain.BaseDirectory
      Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
      //3.項(xiàng)目的目錄
      Console.WriteLine(Path.GetFullPath("../../"));
      Console.ReadKey();
    }

運(yùn)行結(jié)果:

2.winform應(yīng)用程序

private void Form1_Load(object sender, EventArgs e)
    {
      //1.Environment.CurrentDirectory
      txtBox1.Text = Environment.CurrentDirectory;
      //2.Application.StartupPath
      txtBox2.Text = Application.StartupPath;
      //3.Directory.GetCurrentDirectory()
      txtBox3.Text = Directory.GetCurrentDirectory();
      //4.AppDomain.CurrentDomain.BaseDirectory
      txtBox4.Text = AppDomain.CurrentDomain.BaseDirectory;
    }

運(yùn)行結(jié)果:

3.MVC和WebForm項(xiàng)目

通過(guò)Server.MapPath("/")獲取根目錄

//WebForm
 <h1><%=Server.MapPath("/") %></h1>
//Mvc
 <h1>@Server.MapPath("/")</h1>

4.WebApi項(xiàng)目

public class ValuesController : ApiController
  {
    //api/values
    public string Get()
    {
      return System.Web.Hosting.HostingEnvironment.MapPath("/");
    }
   }

WebApi Core的根目錄獲?。篐ttpRuntime.AppDomainAppPath

補(bǔ)充:WebForm /Mvc /WebApi項(xiàng)目的根目錄為配置文件Web.config所在的目錄。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#中foreach語(yǔ)句深入研究

    C#中foreach語(yǔ)句深入研究

    這篇文章主要介紹了C#中foreach語(yǔ)句深入研究,本文通過(guò)手動(dòng)實(shí)現(xiàn)迭代器來(lái)了解foreach語(yǔ)句的本質(zhì),揭示其原理,需要的朋友可以參考下
    2015-06-06
  • 最新評(píng)論

    河曲县| 克东县| 绍兴县| 南漳县| 柞水县| 深水埗区| 庆安县| 万宁市| 吉安县| 卓资县| 祁阳县| 阿图什市| 西峡县| 县级市| 廊坊市| 砀山县| 阿合奇县| 新民市| 临朐县| 瓮安县| 页游| 淅川县| 吴旗县| 临安市| 利川市| 晴隆县| 盘山县| 方山县| 油尖旺区| 界首市| 乐亭县| 靖边县| 双桥区| 沙洋县| 沐川县| 扶沟县| 东辽县| 嘉黎县| 湖北省| 武安市| 绵阳市|