【发布时间】:2012-09-02 15:15:45
【问题描述】:
如果我使用 Application.StartupPath 或 AppDomain.CurrentDomain.BaseDirectory 它在 bin\debug 文件夹中搜索文件 但我必须在 mac # .net 项目中使用我的根目录“Resources\imagefile.png”中的文件夹!
Filestream fs;
fs = new Filestream(AppDomain.CurrentDomain.BaseDirectory + "folder\\imagefile.png");
那么应该如何编写代码来从我的根目录读取文件,尽管使用上面的代码或目录的完整路径是“@C:.......”,甚至 Server.MapPath 是我们不能使用。
获取我的应用程序路径,但这给出了类似的东西 C:\Projects\XYZ\ABC\bin\Debug
我不想要 bin\Debug 。有什么方法可以实现吗?
【问题讨论】:
-
检查这个 SO 问题:Path to resource files in a VS2010 project
-
我只需要主应用程序文件夹,我就这样想通了;字符串路径 = AppDomain.CurrentDomain.BaseDirectory.IndexOf("bin")) + @"\ImageName.jpg");
标签: c# .net winforms filestream windows-applications