C # console application: help file without .. \ .. \ filename

I need to read data from a file in a C # console application.
What works:new StreamReader(@"..\\..\myData.csv");

Problem: it ..\\..\works because my exe file is in the bin / Debug directory. When I deploy my project, the path no longer works

Question: How can I link to myData.csv regardless of the location of the exe file?

I was hoping to find a method that returns the "root" of my console application. So far I have tried the following:

Process.GetCurrentProcess().MainModule.FileName
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location
Path.GetFullPath("bp.csv")
AppDomain.CurrentDomain.BaseDirectory
Directory.GetCurrentDirectory()

All these expressions lead me to the directory of the exe file, and not to the root.

I was just starting to read about isolated storage, but it would be nice to have something simpler. Any suggestions / recommendations?

+3
3

, , CSV VS ", ", .exe( Debug Release ) .

:

string folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

CSV:

string filePath = Path.Combine(folder, "myData.csv");
+5

myData.csv? .

  • , exe,

    new StreamReader("myData.csv");
    
  • App.Conig .

  • , PATH.

+2

new StreamReader("myData.csv");

, , .exe.

-, ( ), . " " , , .

, n - , $(ProjectPath), , , $(TargetDir) , .

0

Source: https://habr.com/ru/post/1778563/


All Articles