How to read existing text files without defining path

后端 未结 8 1012
太阳男子
太阳男子 2020-12-14 05:53

Most of the examples shows how to read text file from exact location (f.e. \"C:\\Users\\Owner\\Documents\\test1.txt\"). But, how to read text files without writing full path

8条回答
  •  旧巷少年郎
    2020-12-14 06:14

    You could use Directory.GetCurrentDirectory:

    var path = Path.Combine(Directory.GetCurrentDirectory(), "\\fileName.txt");
    

    Which will look for the file fileName.txt in the current directory of the application.

提交回复
热议问题