How to get current working directory path c#?

后端 未结 7 1015
清歌不尽
清歌不尽 2020-12-15 15:08

I have a cursor file in project. I have given the absolute path in code i.e

F:/r.cur  

the problem is this is hard-coded path And i Want

相关标签:
7条回答
  • 2020-12-15 16:00

    You can also get by
    System.IO.Directory.GetCurrentDirectory();
    but it shows bin and debug folder also, if you don't want these folder so you can use that code :

    string page = "E:\abccom\Cat\Mouse.aspx"
    
    string name = Path.GetFileName(page );
    string nameKey = Path.GetFileNameWithoutExtension(page );
    string directory = Path.GetDirectoryName(page );
    
    Console.WriteLine("{0}, {1}, {2}, {3}",
    page, name, nameKey, directory);
    

    Output:

    GetFileName:                                        Mouse.aspx
    GetFileNameWithoutExtension:           Mouse
    GetDirectoryName:                              E:\abccom\Cat

    Happy Coding :)

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