Kir*_*kar 5 .net c# filestream winforms windows-applications
如果我使用Application.StartupPath或AppDomain.CurrentDomain.BaseDirectory它在bin\debug文件夹中搜索该文件,但是我必须在ma c#.net项目中使用我的根目录"Resources\imagefile.png"中的文件夹!
Filestream fs;
fs = new Filestream(AppDomain.CurrentDomain.BaseDirectory + "folder\\imagefile.png");
Run Code Online (Sandbox Code Playgroud)
那么如果使用上面的代码或"@C:......."目录的完整路径,如何编写代码来从我的根目录中读取文件,甚至Server.MapPath是我们无法使用的.
要获取我的应用程序路径,但这会产生类似C:\ Projects\XYZ\ABC\bin\Debug的内容
我不想bin\Debug.有没有办法实现这个?
小智 4
通过使用Environment.CurrentDirectory
string yourpath = Environment.CurrentDirectory + @"\YourImage.jpg";
FileStream stream = new FileStream(yourpath, FileMode.Open, FileAccess.Read);
Image image = Image.FromStream(stream);
stream.Close();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21230 次 |
| 最近记录: |