Random ran = new Random();
int i = ran.Next(100,500);
string imastr=newpath.Replace("_","")+i.ToString()+"."+nam;
string imadbstr="photo/"+imastr;
myFile.PostedFile.SaveAs(Server.MapPath(imadbstr)); 
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(imadbstr));
System.Drawing.Image image1 = image;
image1 = image1.GetThumbnailImage(200,150,null,IntPtr.Zero);
string newsmallfile="small"+imastr;
string newsmallima="photo/"+newsmallfile;
image1.Save(Server.MapPath(newsmallima));
image.Dispose();
image1.Dispose();UP图片 一同得到小图片
正常
现在想在保存图片时候 做个判断
把如下代码放在上面代码之下
if(可以寸)
{
myFile.PostedFile.SaveAs(Server.MapPath(imadbstr)); 
image1.Save(Server.MapPath(newsmallima));
image.Dispose();
image1.Dispose();}
else
{
不存
}
结果
异常详细信息: System.IO.FileNotFoundException: F:\aaa\photo\member_photo\2005922162.gif
源错误: System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(imadbstr));

解决方案 »

  1.   

    没有找到图片文件;看看这个路径的实际地址,Server.MapPath(imadbstr)
    这个文件没有找到
      

  2.   

    这句话有问题
    string imastr=newpath.Replace("_","")+i.ToString()+"."+nam;
      

  3.   

    没有做判断
    即不加下面的IF ELSE
    就OK
      

  4.   

    Random ran = new Random();
    int i = ran.Next(100,500);
    string imastr=newpath.Replace("_","")+i.ToString()+"."+nam;
    string imadbstr="photo/"+imastr;
    myFile.PostedFile.SaveAs(Server.MapPath(imadbstr)); 
    System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(imadbstr));
    System.Drawing.Image image1 = image;
    image1 = image1.GetThumbnailImage(200,150,null,IntPtr.Zero);
    string newsmallfile="small"+imastr;
    string newsmallima="photo/"+newsmallfile;
    image1.Save(Server.MapPath(newsmallima));
    image.Dispose();
    image1.Dispose();以上代码 运行非常OK
    该成IF ELSE 就非常不OK!!!
      

  5.   

    那个判断表复杂
    大概思路是if(判断数据表该用户发了几张图片)
    {保存}
    else
    {不保存}