2010-08-20 145 views
0

我正在使用文件上传控件上传图片。 在iam检查条件,如果Image.Width> 250 || Image.Height> 400然后我调整图像大小。 但它给出错误 “SaveAs方法被配置为需要一个根路径,并且路径'ProductImages/roman_sandals.jpg'没有根。”上传时调整图片的大小

ProductImages是我保存图像的文件夹。 任何人都可以发现这是为什么给错误,我的代码是

string strBigServerPath = AppHardcodeValue.productImgPath; 
      string strFileName = ""; 
      if (prodImg.HasFile) 
      { 
       strFileName = prodImg.PostedFile.FileName; 
       string uniqueNum = Convert.ToString(System.Guid.NewGuid()); 
       string shortFileName = System.IO.Path.GetFileName(strFileName); 
       string Extension = System.IO.Path.GetExtension(prodImg.FileName); 
       string newFileName = shortFileName; 
       prodImg.SaveAs(Server.MapPath(strBigServerPath + newFileName)); 
       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, 400); 
         using (System.Drawing.Image ImgThnail = 
           new Bitmap(Img, MainSize.Width, MainSize.Height)) 
         { 
          prodImg.SaveAs(strBigServerPath + newFileName); 
         } 
        } 
        Img.Dispose(); 
       } 
       string ThumbnailPath = Server.MapPath(AppHardcodeValue.productThumbImgPath) + newFileName; 
       using (System.Drawing.Image Img = 
        System.Drawing.Image.FromFile(Server.MapPath(strBigServerPath) + newFileName)) 
       { 
        Size ThumbNailSize = new Size(50, 50); 

        using (System.Drawing.Image ImgThnail = 
         new Bitmap(Img, ThumbNailSize.Width, ThumbNailSize.Height)) 
        { 
         ImgThnail.Save(ThumbnailPath, Img.RawFormat); 
         ImgThnail.Dispose(); 
        } 
        Img.Dispose(); 
       } 

} 

回答