开发者

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

开发者 https://www.devze.com 2023-02-04 10:06 出处:网络
I have image files stored in \"VS_Project\\Resources\\Images\". When I use the following code: String str = Server.MapPath(\"a.png\");

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

精彩评论

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

关注公众号