【发布时间】:2011-04-04 17:38:17
【问题描述】:
我正在使用文件上传控件上传图像。 但它给出了错误, SaveAs方法配置为需要root路径,路径'~/Admin/ProductImages/images(5).jpg'没有root。
字符串 strBigServerPath = "~/Admin/ProductImages/"; 字符串 strFileName = ""; 字符串图像名 = "";
if (prodImg.HasFile)
{
strFileName = prodImg.PostedFile.FileName;
prodImg.PostedFile.SaveAs(imgPath + strFileName);
string[] ext = strFileName.Split('.');
string newProductFileName = ext[0] + "123";
ImageName = newProductFileName + "." + ext[1];
prodImg.PostedFile.SaveAs(imgPath + ImageName);
using (System.Drawing.Image Img =
System.Drawing.Image.FromFile(Server.MapPath(strBigServerPath) + newFileName))
{
if (Img.Width > 250 && Img.Height > 400)
{
Size MainSize = new Size(250, 300);
using (System.Drawing.Image ImgThnail =
new Bitmap(Img, MainSize.Width, MainSize.Height))
{
ImgThnail.Save(Server.MapPath(strBigServerPath) + ImageName);
}
}
Img.Dispose();
}
【问题讨论】:
标签: asp.net file-upload