protected void Button1_Click1(object sender, EventArgs e)
        {
           
            HttpPostedFile hpf = FileUpload1.PostedFile;            // 取得文件路径             string filePath = hpf.FileName;            // 从路径中取出文件名用来作为保存的文件名             string filePath1 = Path.GetFileName(filePath);            // 取得服务器站点根目录的绝对路径             string serverPath = Server.MapPath("~/");            // 保存文件             hpf.SaveAs(serverPath + filePath);           // Response.Redirect("A.aspx");
       //---------------------------------------------------------------------------------------//
“/”应用程序中的服务器错误。
--------------------------------------------------------------------------------未能找到路径“F:\WEB\Web\Web\”的一部分。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.IO.DirectoryNotFoundException: 未能找到路径“F:\WEB\Web\Web\”的一部分。源错误: 
行 77:             // 保存文件 
行 78: 
行 79:             hpf.SaveAs(serverPath + filePath);
行 80: 
行 81:            // Response.Redirect("A.aspx");
 源文件: F:\WEB\Web\Web\Default.aspx.cs    行: 79 堆栈跟踪: 
[DirectoryNotFoundException: 未能找到路径“F:\WEB\Web\Web\”的一部分。]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +492
   System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1038
   System.IO.FileStream..ctor(String path, FileMode mode) +64
   System.Web.HttpPostedFile.SaveAs(String filename) +87
   Web._Default.Button1_Click1(Object sender, EventArgs e) in F:\WEB\Web\Web\Default.aspx.cs:79
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746 
望高手解答,小弟新手

解决方案 »

  1.   

    string filePath = hpf.FileName 获取的是本地文件件路径试试下面:
    string filePath = hpf.FileName; 
    string filename=filePath.SubString(filePath.Lastindexof("\\"+1);
    string serverPath = Server.MapPath("/"); 
    hpf.SaveAs(serverPath + filename); 
      

  2.   

    提示这个错误StartIndex 不能小于 0。
    参数名: startIndex 
      

  3.   

      //上传图片
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (UploadFile.Value == null || UploadFile.Value == "")
            {
                PageAlert("noup1", "请选择要上传的图片");
                return;
            }
            if (UploadFile.Value != null && UploadFile.Value != "")
            {
                if (IsAllowedExtension(UploadFile))
                {
                    //上传文件             
                    string extension = Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper();
                    Random rom = new Random();
                    string fileName = "n" + DateTime.Now.ToString("yyyyMMddhhmmss");
                      HttpPostedFile pf = UploadFile.PostedFile;                              pf.SaveAs(Server.MapPath("../") + "Upload/" + fileName + extension);               
                    mFileName = fileName + extension;
                    string path = Server.MapPath("../") + "Upload/" + fileName + extension;                          
                    
                  
                }
                else
                {
                    PageAlert("geshi1", "图片只支持GIF,JPG,BMP格式,请检查一下图片");
                    return;
                }       
              
            }
           
        }
      

  4.   

    string filename=filePath.SubString(filePath.LastIndexOf("\\")+1);
    不好意思刚才缺了)
      

  5.   

    不过还想问下,可以上传到指定文件夹下不,string serverPath = Server.MapPath("~/image");我在后面添加了image为什么无法保存到image文件夹中去? 
      

  6.   

    刚刚那位朋友还在不,string serverPath = Server.MapPath("~/image");我在后面添加了image为什么无法保存到image文件夹中去?