繁体   English   中英

如何使用Server.MapPath读取相对Web路径,并在文件名或C#中使用空格字符

[英]How to read a relative web path with Server.MapPath with space character in filename or path in C#

我得到的是

src = Request.QueryString["imgsrc"];//src = "images/file 15.jpeg";

System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(src));

第二行返回System.IO.FileNotFoundException导致路径空间不足的原因。

我应该怎么做才能编码或做些什么来读取这种路径?

将Server.MapPath(src)分配给一个临时变量,然后确保路径指向现有文件:

src = Request.QueryString["imgsrc"];//src = "images/file 15.jpeg";

string tempPath = Server.MapPath(src);

Debug.Assert(System.IO.File.Exists(tempPath);

System.Drawing.Image image = System.Drawing.Image.FromFile(tempPath);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM