How to read a file in the root directory of a Windows application in C # .net?

If I use Application.StartupPath or AppDomain.CurrentDomain.BaseDirectory This is a search in the bin \ debug folder for the file but I have to use the folder from my root directory "Resources \ imagefile.png" in the ma C # .net project!

Filestream fs;
fs = new Filestream(AppDomain.CurrentDomain.BaseDirectory + "folder\\imagefile.png");

So, how to write code to read the file from my root directory, despite using the above code or the full path to the directory, which is "@C: .......", and even Server.MapPath - we can’t use it .

To get my path to the application, but it gives something like C: \ Projects \ XYZ \ ABC \ Bin \ Debug

I do not want bin \ Debug. Is there any way to achieve this?

+5
source share
2 answers

Environment.CurrentDirectory

string yourpath = Environment.CurrentDirectory + @"\YourImage.jpg";
FileStream stream = new FileStream(yourpath, FileMode.Open, FileAccess.Read);
Image image = Image.FromStream(stream);
stream.Close(); 
+4

, bin. /, " " - .

+4

All Articles