来自文件的图像,服务器MapPath

时间:2012-05-17 15:14:26

标签: asp.net

为什么这样做:

System.Drawing.Image imageBmp =
System.Drawing.Image.FromFile(Server.MapPath("~/Images/Image.jpg"));
imageBmp.Save(Server.MapPath("~/Images2/Image.jpg"),  
System.Drawing.Imaging.ImageFormat.Bmp);
Bitmap bmp = new Bitmap(imageBmp);

这不是吗? (文件名正确)

var fileName = Request.QueryString["name"];
System.Drawing.Image imageBmp = 
System.Drawing.Image.FromFile(Server.MapPath("~/Images/" + fileName));
imageBmp.Save(Server.MapPath("~/Images/" + fileName),
System.Drawing.Imaging.ImageFormat.Bmp);
Bitmap bmp = new Bitmap(imageBmp);

1 个答案:

答案 0 :(得分:1)

此行会尝试将文件保存到自身imageBmp.Save(Server.MapPath("~/Images/" + fileName), System.Drawing.Imaging.ImageFormat.Bmp);

应为imageBmp.Save(Server.MapPath("~/Images2/" + fileName), System.Drawing.Imaging.ImageFormat.Bmp);