If i use Application.StartupPath or AppDomain.CurrentDomain.BaseDirectory It Search in a bin\debug folder for the file but I have to use a folder from my root directory "Resources\imagefile.png" in ma c# .net project!
Filestream fs;
fs = new Filestream(AppDomain.CurrentDomain.BaseDirectory + "folder\\imagefile.png");
So how should write code to read file from my root directory in spite of using above code or a full path of the directory that is "@C:......." and even Server.MapPath is we cant use.
To get my application path ,but this gives something like C:\Projects\XYZ\ABC\bin\Debug
i don't want bin\Debug .Is there any way to achieve this ?
By Using the Environment.CurrentDirectory
string yourpath = Environment.CurrentDirectory + @"\YourImage.jpg";
FileStream stream = new FileStream(yourpath, FileMode.Open, FileAccess.Read);
Image image = Image.FromStream(stream);
stream.Close();
Generally, you'd set those items to be copied into the bin folder. Right click in solution explorer/navigator, choose properties and set "Copy to output directory" to something different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With