C# 中的各种路径

1 篇文章 0 订阅

控制台应用程序中的路径

static void Main(string[] args)
        {
            Console.WriteLine("Environment.CurrentDirectory:" + Environment.CurrentDirectory);
            Console.WriteLine("AppDomain.CurrentDomain.BaseDirectory:"+AppDomain.CurrentDomain.BaseDirectory);
            Console.WriteLine("项目根目录:"+Path.GetFullPath("../../"));
            Console.ReadKey();
        }
  • Environment.CurrentDirectory:D:\Cpeoject\ConsolePath\bin\Debug

  • AppDomain.CurrentDomain.BaseDirectory:D:\Cpeoject\ConsolePath\bin\Debug\

  • 项目根目录:D:\Cpeoject\ConsolePath\

Form中的路径

			Dictionary<string, string> formPathDic = new Dictionary<string, string>();
            string path1 = Environment.CurrentDirectory;
            formPathDic.Add("Environment.CurrentDirectory", path1);
            string path2 = Application.StartupPath;
            formPathDic.Add("Application.StartupPath", path2);
            string path3 = Directory.GetCurrentDirectory();
            formPathDic.Add("Directory.GetCurrentDirectory()", path3);
            string path4 = AppDomain.CurrentDomain.BaseDirectory;
            formPathDic.Add("AppDomain.CurrentDomain.BaseDirectory", path4);
            string path6 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            formPathDic.Add("SetupInformation.ApplicationBase",path6);
            string path7 = Process.GetCurrentProcess().MainModule.FileName;
            formPathDic.Add("MainModule.FileName",path7);
            string path8 = Application.ExecutablePath;
            formPathDic.Add("Application.ExecutablePath", path8);
            DirectoryInfo dire = Directory.GetParent(Directory.GetCurrentDirectory());
            string path9 = dire.Parent.FullName;
            formPathDic.Add("RootPath",path9);

            foreach (KeyValuePair<string, string> kvp in formPathDic)
            {
                listBox1.Items.Add(kvp.Key);
                listBox2.Items.Add(kvp.Value);
            }

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值