开发者

ASP.NET Server.MapPath not returning full path of a file

I have image files stored in "VS_Project\Resources\Images".

When I use the following code:

String str = Server.MapPath("a.png");

str becomes "VS_Project\a.png".

Why isn't it returning the f开发者_开发知识库ull path?


You need a / before the a.png. If Path starts with either a forward (/) or backward slash (\), the MapPath method returns a path as if Path were a full, virtual path. If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the .asp file being processed.


Try this:

string str = Server.MapPath("/") + "\\Resources\\Images\\a.png";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜