怎么在代码里应用文件的相对路径啊?

intelserver 2004-06-10 04:54:01
比如
Bitmap bmp = new Bitmap(@"\abc.bmp");

表示将当前目录下的文件构建成bmp对象。
但是提示找不到文件。
...全文
221 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
marvelstack 2004-06-12
  • 打赏
  • 举报
回复
在C#里面获得应用程序的当前路径

Environment.CurrentDirectory
获取应用程序的当前工作目录。
System.IO.Directory.GetCurrentDirectory()
AppDomain.CurrentDomain.BaseDirectory
Application.StartupPath
Application.ExecutablePath
--获取和设置当前目录(即该进程从中启动的目录)的完全限定路径。
yanransoft 2004-06-12
  • 打赏
  • 举报
回复
agree yadongfile(间间)
sharpdew 2004-06-10
  • 打赏
  • 举报
回复
liduke(天下有雪) is right!
liduke 2004-06-10
  • 打赏
  • 举报
回复
Application.StartupPath 在WINFORM中
Server.MapPath 在WEBFORM中
cimoka 2004-06-10
  • 打赏
  • 举报
回复
用System.AppDomain.CurrentDomain.BaseDirectory
可以得到当前程序的根目录

你也可以直接使用".\customer.mdb","..\customer.mdb"
还可以使用 Application.StartUpPath来获得当前应用的所在路径

str=Path.GetExtension(Application.ExecutablePath)+"\n";
str=str+Path.GetFileNameWithoutExtension(Application.ExecutablePath)+"\n";
str=str+Path.GetPathRoot(Application.ExecutablePath)+"\n";
str=str+Application.ExecutablePath+"\n";
str=str+Path.GetDirectoryName(Application.ExecutablePath)+"\n";


反射:
System.Reflection.Assembly.GetExecutingAssembly().Location
andersky 2004-06-10
  • 打赏
  • 举报
回复
.\*.*表示当前程序的目录路径
..\* .*表示程序上一级目录的路径
yadongfile 2004-06-10
  • 打赏
  • 举报
回复
string bmp=GetApplicationPath()+"\\abc.bmp";
public static string GetApplicationPath()
{
return Application.StartupPath;
}
fly2008fly 2004-06-10
  • 打赏
  • 举报
回复
当前目录 Bitmap(@"abc.bmp");
../ 表示回退
比如从 a文件夹页面abc.aspx到b文件页面efg.aspx
要这样Response.Redirect(@"..\b\efg.aspx");
darkness1978 2004-06-10
  • 打赏
  • 举报
回复
\bin\debug\里有这个文件吗?

minajo21 2004-06-10
  • 打赏
  • 举报
回复
Application.StartupPath

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧