How can I get the application's path in a .NET console application?

后端 未结 27 1416
甜味超标
甜味超标 2020-11-21 11:11

How do I find the application\'s path in a console application?

In Windows Forms, I can use Application.StartupPath to find the current path, but this d

27条回答
  •  天涯浪人
    2020-11-21 12:04

    You can create a folder name as Resources within the project using Solution Explorer,then you can paste a file within the Resources.

    private void Form1_Load(object sender, EventArgs e) {
        string appName = Environment.CurrentDirectory;
        int l = appName.Length;
        int h = appName.LastIndexOf("bin");
        string ll = appName.Remove(h);                
        string g = ll + "Resources\\sample.txt";
        System.Diagnostics.Process.Start(g);
    }
    

提交回复
热议问题