string ext = null, path = null, newFileName = null;
        System.Drawing.Image image, newImage;
        if (FileUpload1.PostedFile.FileName.ToString() != null && FileUpload1.PostedFile.FileName.ToString() != "")
        {
            
            //载入原图
            image = System.Drawing.Image.FromFile(FileUpload1.PostedFile.FileName.ToString());
            //回调
            System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(callBack);
            //生成缩略图
            newImage = image.GetThumbnailImage(100, 100, callb, new System.IntPtr());
            image.Dispose();
            newImage.Dispose();
            
            if (FileUpload1.PostedFile != null)
            {
                //判断是不是图像文件
                if (FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
                {
                    Response.Write("文件类型错误");//文件类型错误
                }
                else
                {
                    ext = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf("."));
                    //生成新的原文件名 年月日+文件大小+扩展名
                    path = "upload/" + System.DateTime.Now.Date.ToShortDateString() + FileUpload1.PostedFile.ContentLength.ToString() + ext;
                    
                    //缩略图文件名
                    newFileName = "upload/" + System.DateTime.Now.Date.ToShortDateString() + FileUpload1.PostedFile.ContentLength.ToString() + "small"+ext;
                    //上传缩略图
                   // Response.Write(newFileName);
                    FileUpload1.PostedFile.SaveAs(Server.MapPath(newFileName));
                    FileUpload1.PostedFile.SaveAs(Server.MapPath(path));                }
            }
        }
//当在客户机上提交图片时
E:\我的文档\maximize.png 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.FileNotFoundException: E:\我的文档\maximize.png菜鸟求解

解决方案 »

  1.   

    //载入原图
    image = System.Drawing.Image.FromFile(FileUpload1.PostedFile.FileName.ToString());我晕,这是直接从硬盘上读文件
    哪里是文件上传啊?
    FileUpload1.PostedFile.FileName是客户端路经
      

  2.   

    如何修改下啊 我不懂.net
    一个MM写的 老是问我 不得不跑这.net区 郁闷
      

  3.   

    image = System.Drawing.Image.FromFile(FileUpload1.PostedFile.FileName.ToString());改为image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream)
      

  4.   

    private string UpPic(FileUpload upfile, string filePath, ref bool ok)
        {
            string NewName = "";
            string PicUrl = "";
            try
            {
                if (upfile.HasFile)
                {
                    if (!System.IO.Directory.Exists(Server.MapPath(filePath)))
                    {
                        System.IO.Directory.CreateDirectory(Server.MapPath(filePath));
                    }                int index = upfile.FileName.IndexOf(".");
                    string ExtName = upfile.FileName.Substring(index);
                    if (ExtName != ".jpg" && ExtName != ".gif" && ExtName != ".bmp")
                    {
                        JScript.Alert("提示:图片格式非法!");
                        ok = false;
                        return "";
                    }
                    NewName = System.Guid.NewGuid().ToString() + ExtName.ToLower();
                    upfile.PostedFile.SaveAs(Server.MapPath(filePath + @"\") + NewName);
                }            PicUrl = filePath.Replace("../", "") + NewName;
            }
            catch
            {
                ok = false;
            }
            return PicUrl;
        }
      

  5.   

    if (ExtName != ".jpg" && ExtName != ".gif" && ExtName != ".bmp")
                    {
                        JScript.Alert("提示:图片格式非法!");
                        ok = false;
                        return "";
                    }
    这句删掉,可以用你自己的判断
      

  6.   

    To:维也纳
    改后又有新问题:
    未能找到路径“D:\aaaa\Admin\upload\2007-5-10225small.png”的一部分。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.DirectoryNotFoundException: 未能找到路径“D:\aaaa\Admin\upload\2007-5-10225small.png”的一部分。
      

  7.   

    汗 解决了 狂晕
    MM没有在目录下建upload文件夹