我这有一个图片上传的小例子在本地测试时一切正常,但是发布以后上传到空间就出现问题了提示“未能找到路径“C:\Documents and Settings\Administrator\桌面\临时图片\小贝1.jpg”的一部分。 ”代码如下:        if (FileUpload1.HasFile)
        {
            string fileContentType = FileUpload1.PostedFile.ContentType;
            if (fileContentType == "image/bmp" || fileContentType == "image/gif" || fileContentType == "image/png" || fileContentType == "image/pjpeg")
            {
                string name = FileUpload1.PostedFile.FileName; // 客户端文件路径 
                FileInfo file = new FileInfo(name);
               // string fid = this.Label1.Text;
                string fid = this.idnum.Text;
                string fileName = file.Name; // 文件名称 
                string fileName_s = "thumb-" +file.Name ; // 缩略图文件名称 
                string fileName_sy = "image-" + file.Name; // 水印图文件名称(文字) 
                string fileName_syp = "syp_" + fid + file.Name; // 水印图文件名称(图片) 
                string webFilePath = Server.MapPath("~/images/chanpin-image/file/" + fileName); // 服务器端文件路径 
                string webFilePath_s = Server.MapPath("~/images/chanpin-image/X-images/" + fileName_s);  // 服务器端缩略图路径 
                string webFilePath_sy = Server.MapPath("~/images/chanpin-image/D-images/" + fileName_sy); // 服务器端带水印图路径(文字) 
                string webFilePath_syp = Server.MapPath("~/images/chanpin-image/upfile/" + fileName_syp); // 服务器端带水印图路径(图片) 
                string webFilePath_sypf = Server.MapPath("~/images/chanpin-image/shuiyinfile/shuiyin.jpg"); // 服务器端水印图路径(图片)                 FileStream fs = File.OpenRead(name);
                string type = name.Substring(name.LastIndexOf(".") + 1);

解决方案 »

  1.   

                    string dimg = "images/chanpin-image/D-images/" + fileName_sy;
                    string ximg = "images/chanpin-image/X-images/" + fileName_s;
                    Product2 pt2 = new Product2();
                    pt2.DIMG = dimg;
                      byte[] content = new byte[fs.Length];
                    fs.Read(content, 0, content.Length);
                    fs.Close();                SqlConnection conn = new SqlConnection("data source=.; initial catalog=zhuoye;user id=sa;pwd=;");
                    SqlCommand cmd = conn.CreateCommand();
                    conn.Open();                cmd.CommandText = "insert into ChanPin (CP_ID,CP_Name,CP_Num,CP_Dimg,CP_Ximg,CP_Date,Image_Sencer,Effective_Pixels,Signal_System,Horizontal_Resolution,Shutter_Speed,White_Balance,S_N_Ratio,Minimum_Illumination,Video_Output,Backlight_Compensation,Operation_Temperature,Operation_Temperature2,Sync_System,Dimensions,NW_GW,LED_number,Infraed_Lamps,JiaGe,Image_Content) values (@id,@CP_Name,@CP_Num,@CP_Dimg,@CP_Ximg,@CP_Date,@Image_Sencer,@Effective_Pixels,@Signal_System,@Horizontal_Resolution,@Shutter_Speed,@White_Balance,@S_N_Ratio,@Minimum_Illumination,@Video_Output,@Backlight_Compensation,@Operation_Temperature,@Operation_Temperature2,@Sync_System,@Dimensions,@NW_GW,@LED_number,@Infraed_Lamps,@JiaGe,@content)";
                    cmd.CommandType = CommandType.Text;
                    if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")
                    {
                  pt2.XIMG = ximg;
      

  2.   

                            FileUpload1.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 
                            AddShuiYinword(webFilePath, webFilePath_sy);
                            AddShuiYinPic(webFilePath, webFilePath_syp, webFilePath_sypf);
                            MakeThumbnail(webFilePath, webFilePath_s, 200, 200, "Cut"); // 生成缩略图方法 
                            Label2.Text = "提示:文件“" + fileName + "”上传成功“";
      

  3.   

    C:\Documents and Settings\Administrator\桌面\临时图片\小贝1.jpg
    很明显,是你客户端的文件路径,服务器上是没有这个路径和权限的。你们哪行的错误,就将这行的文件路径修改成服务器端的,Server.MapPath()方法转换成服务器端的路径
      

  4.   

                    string name = FileUpload1.PostedFile.FileName; // 客户端文件路径                 FileInfo file = new FileInfo(name);
                   // string fid = this.Label1.Text;
                    string fid = this.idnum.Text;
                    string fileName = file.Name; // 文件名称 
                    string fileName_s = "thumb-" +file.Name ; // 缩略图文件名称 
                    string fileName_sy = "image-" + file.Name; // 水印图文件名称(文字) 
                    string fileName_syp = "syp_" + fid + file.Name; // 水印图文件名称(图片) 
                    string webFilePath = Server.MapPath("~/images/chanpin-image/file/" + fileName); // 服务器端文件路径 
                    string webFilePath_s = Server.MapPath("~/images/chanpin-image/X-images/" + fileName_s);  // 服务器端缩略图路径 
                    string webFilePath_sy = Server.MapPath("~/images/chanpin-image/D-images/" + fileName_sy); // 服务器端带水印图路径(文字) 
                    string webFilePath_syp = Server.MapPath("~/images/chanpin-image/upfile/" + fileName_syp); // 服务器端带水印图路径(图片) 
                    string webFilePath_sypf = Server.MapPath("~/images/chanpin-image/shuiyinfile/shuiyin.jpg"); // 服务器端水印图路径(图片) 
             
      

  5.   

    string name = FileUpload1.PostedFile.FileName; // 客户端文件路径
    string fName = Path.GetFileName(FileUpload1.PostedFile.FileName);
    string saveFileName = Server.MapPath(string.Format("FileUpLoadSavePath/{0}", fName));
    FileUpload1.SaveAs(saveFileName);
    FileInfo file = new FileInfo(saveFileName);下面就是你自己的处理代码了,这样就可以了
      

  6.   

    string name =FileUpload1.PostedFile.FileName; // 客户端文件路径 
     FileInfo file = new FileInfo(name);
     string fid = this.idnum.Text;
     string fileName = file.Name; // 文件名称 
     string fileName_s = "thumb-" +file.Name ; // 缩略图文件名称 
     string fileName_sy = "image-" + file.Name; // 水印图文件名称(文字) 
     string fileName_syp = "syp_" + fid + file.Name; // 水印图文件名称(图片) 
     string webFilePath = Server.MapPath("~/images/chanpin-image/file/" + fileName); // 服务器端文件路径 
    string webFilePath_s = Server.MapPath("~/images/chanpin-image/X-images/" + fileName_s);  // 服务器端缩略图路径 
    string webFilePath_sy = Server.MapPath("~/images/chanpin-image/D-images/" + fileName_sy); // 服务器端带水印图路径(文字) 
    string webFilePath_syp = Server.MapPath("~/images/chanpin-image/upfile/" + fileName_syp); // 服务器端带水印图路径(图片) 
    string webFilePath_sypf = Server.MapPath("~/images/chanpin-image/shuiyinfile/shuiyin.jpg"); // 服务器端水印图路径(图片) 
    FileStream fs = File.OpenRead(name);
    string type = name.Substring(name.LastIndexOf(".") + 1);
      

  7.   

    string name = FileUpload1.PostedFile.FileName; // 客户端文件路径 
    string fName = Path.GetFileName(FileUpload1.PostedFile.FileName); 
    string saveFileName = Server.MapPath(string.Format("FileUpLoadSavePath/{0}", fName)); 
    FileUpload1.SaveAs(saveFileName); //这个代码一定要在你建立“FileInfo”之前调用
    FileInfo file = new FileInfo(saveFileName); 
    string fid = this.idnum.Text; 
    string fileName = file.Name; // 文件名称 
    string fileName_s = "thumb-" +file.Name ; // 缩略图文件名称 
    string fileName_sy = "image-" + file.Name; // 水印图文件名称(文字) 
    string fileName_syp = "syp_" + fid + file.Name; // 水印图文件名称(图片) 
    string webFilePath = Server.MapPath("~/images/chanpin-image/file/" + fileName); // 服务器端文件路径 
    string webFilePath_s = Server.MapPath("~/images/chanpin-image/X-images/" + fileName_s);  // 服务器端缩略图路径 
    string webFilePath_sy = Server.MapPath("~/images/chanpin-image/D-images/" + fileName_sy); // 服务器端带水印图路径(文字) 
    string webFilePath_syp = Server.MapPath("~/images/chanpin-image/upfile/" + fileName_syp); // 服务器端带水印图路径(图片) 
    string webFilePath_sypf = Server.MapPath("~/images/chanpin-image/shuiyinfile/shuiyin.jpg"); // 服务器端水印图路径(图片) 
    FileStream fs = File.OpenRead(name); 
    string type = name.Substring(name.LastIndexOf(".") + 1); 
      

  8.   

    你自己一定要注意我加红的地方,同时要在网站的根目录建立一个“FileUpLoadSavePath”文件夹
    要不你又要出错
      

  9.   

    还是不行啊 提示错误:
    未能找到路径“d:\web\ketong\web\zhuoye\admin\FileUpLoadSavePath\m4.jpg”的一部分。 
    我把FileUpLoadSavePath移动到zhuoye\admin目录下提示错误:
    未能找到路径“C:\Documents and Settings\Administrator\桌面\临时图片\m4.jpg”的一部分。 
      

  10.   

    我从上面的代码发现你有一处没有改过来FileStream fs = File.OpenRead(name); 
    改为FileStream fs = File.OpenRead(fName); 
    string type = name.Substring(name.LastIndexOf(".") + 1); 同志啊,看问题一定要从头开始看,不要只看到一处就改一处,要小心检查每一处
    尤其是用到变量的地方
      

  11.   

    我都改了还是出现:
    未能找到文件“c:\windows\system32\inetsrv\m1.jpg”。 
      

  12.   

                    string name =FileUpload1.PostedFile.FileName; // 客户端文件路径                 string fName = Path.GetFileName(FileUpload1.PostedFile.FileName);
                    string saveFileName = Server.MapPath(string.Format("~/images/chanpin-image/file/{0}", fName));
                    FileUpload1.SaveAs(saveFileName); //这个代码一定要在你建立“FileInfo”之前调用 
                    FileInfo file = new FileInfo(saveFileName); 
                    //FileInfo file = new FileInfo(name);
                   // string fid = this.Label1.Text;
                    string fid = this.idnum.Text;
                    string fileName = file.Name; // 文件名称 
                    string fileName_s = "thumb-" +file.Name ; // 缩略图文件名称 
                    string fileName_sy = "image-" + file.Name; // 水印图文件名称(文字) 
                    string fileName_syp = "syp_" + fid + file.Name; // 水印图文件名称(图片) 
                    string webFilePath = Server.MapPath("~/images/chanpin-image/file/" + fileName); // 服务器端文件路径 
                    string webFilePath_s = Server.MapPath("~/images/chanpin-image/X-images/" + fileName_s);  // 服务器端缩略图路径 
                    string webFilePath_sy = Server.MapPath("~/images/chanpin-image/D-images/" + fileName_sy); // 服务器端带水印图路径(文字) 
                    string webFilePath_syp = Server.MapPath("~/images/chanpin-image/upfile/" + fileName_syp); // 服务器端带水印图路径(图片) 
                    string webFilePath_sypf = Server.MapPath("~/images/chanpin-image/shuiyinfile/shuiyin.jpg"); // 服务器端水印图路径(图片)                 FileStream fs = File.OpenRead(fName);
                    string type = fName.Substring(fName.LastIndexOf(".") + 1);
      

  13.   

    为什么老有人拿着
    C:\Documents and Settings\Administrator\桌面\临时图片\小贝1.jpg 
    这样的路径来问呢?
    这要是能访问到,那你电脑里的东西我不都可以看到了?
    把你的保存路径修改成服务器端的吧。