我在本地上传一张图片到服务器上,,总是报错说找不到我要上传的文件,后来经过测试发现是他把我本地的图片路径读到了服务器上,在服务器上当让是找不到这张图片的,请高手指点下要怎么才能把本地图片上传到服务器
string imgUrl   = ConfigurationManager.AppSettings["ImageUrl"];
            string physicalPath = this.Page.MapPath(@imgUrl);//指定文件上传路径
           // string physicalPath  = this.Page.MapPath(@"..\..\UserImages");//指定文件上传路径
            string fileName      = fScheduleNm + fileType;
            string path_fileName = physicalPath  + fileName;            if (File.Exists(path_fileName))                 {
                File.Delete(path_fileName);
            }
            this.fpdUpload.PostedFile.SaveAs(path_fileName); 

解决方案 »

  1.   

    physicalPath  + fileName 可能有问题?physicalPath 最后有没有"\", 需要测试一下。(physicalPath .EndsWith("\\") ? physicalPath  : physicalPath + "\\") + fileName别是上传成;..\..\UserImagesXXX.xx 而不是..\..\UserImages\XXX.xx 
      

  2.   

    你那樣寫的路徑有問題:改爲這樣,應該可以的
    string physicalPath = System.Web.HttpContext.Current.Request.MapPath("文件夾名"):
    可以先輸出一下看下,如果路徑對的,一定可以上傳.