protected void BtnUpDown_Click(object sender, EventArgs e)
    {
        if (FileUpload1.PostedFile.FileName != "")
        {
            //定义上传路径(在当前目录下的uploadfile文件下)
            string uploadpath = this.Server.MapPath("../picture");
            //取得文件名
            string tmpfilename = FileUpload1.PostedFile.FileName;
            //文件名
            filename = tmpfilename.Substring(tmpfilename.LastIndexOf("\\") + 1);
            //原文件的保存路径
            string fileSavePath = uploadpath + "\\" + filename;
            //保存原图片            
            FileUpload1.SaveAs(fileSavePath);
            //调用生成缩略图程序,生成缩略图及生成写字的图片
            this.toImage(FileUpload1.PostedFile.InputStream, uploadpath, filename);
            //求取后缀名
            string suffix = filename.Substring(filename.LastIndexOf("."));
            //显示图片
            //分别为原图片/写字的图片(多一个w)/缩略图(多一个x)
            this.Image1.ImageUrl = "~/picture/" + filename;
            this.Image2.ImageUrl = "~/picture/" + filename.Replace(suffix, "w" + suffix);
            this.Image3.ImageUrl = "~/picture/" + filename.Replace(suffix, "x" + suffix);
            //显示图像控件
            this.Image1.Visible = true;
            this.Image2.Visible = true;
            this.Image3.Visible = true;
        }
        else
        {
            Response.Write("<script>alert('上传的文件不能为空!');loaction='pic.aspx'</script>");
        }
    }
这段程序调试时出错:“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------未能找到路径“F:\03\PlayVideo\picture\4.jpg”的一部分。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.DirectoryNotFoundException: 未能找到路径“F:\03\PlayVideo\picture\4.jpg”的一部分。源错误: 
行 145:            string fileSavePath = uploadpath + "\\" + filename;
行 146:            //保存原图片            
行 147:            FileUpload1.SaveAs(fileSavePath);
行 148:            //调用生成缩略图程序,生成缩略图及生成写字的图片
行 149:            this.toImage(FileUpload1.PostedFile.InputStream, uploadpath, filename);
 

解决方案 »

  1.   

    ("../picture") 你把 这个改成("~/picture");在单步调试一下!
      

  2.   

    F:\03\PlayVideo\picture\
    你看看你机器上这个路径全不全,一层层的文件夹必需存在,它不会自己创建文件夹
    特别是站点根目录的picture文件夹,特别注意
      

  3.   

    uploadpath + "\\" + filename;
      

  4.   

    System.IO.DirectoryNotFoundException:都出现这个异常了楼主还不清楚吗?在保存文件的时候要先判断目录是否存在,如果不存在则建立!!
      

  5.   

    uploadpath + "\\" + filename 中\\改为/
      

  6.   

    问题已经解决。谢谢你们。是picture名没写对。