string str = “”;
  if (FileUpload1.HasFile)
  {
   try
   {
    str += “Uploading file: “ + FileUpload1.FileName;
    // 保存文件
    FileUpload1.SaveAs(“c:\\websites\\uploads\\” + FileUpload1.FileName);
    // 显示文件信息
    str += “<br/>Saved As: “ + FileUpload1.PostedFile.FileName;
    str += “<br/>File Type: “ + FileUpload1.PostedFile.ContentType;
    str += “<br/>File Length (bytes): “ + FileUpload1.PostedFile.ContentLength;
    str += “<br/>PostedFile File Name: “ + FileUpload1.PostedFile.FileName;
   }
   catch (Exception ex)
   {
    str += “<br/><b>Error</b><br/>Unable to save 
c:\\websites\\uploads\\” + FileUpload1.FileName +“<br/>” + ex.Message;
   }
  }
  else
  {
   str = “没有找到上传文件”;
  }
  lblMessage.Text = str;
  lblDisplay.Text = “”;
 }

解决方案 »

  1.   

    哥们,那是获取不了路径的.FileUpload.PostedFile 你监视一下 里面是没有你选中本机上的路径的.
      

  2.   


    if (this.FUP.HasFile)//检查是否有文件
            {
               string fullFileName = this.FUP.PostedFile.FileName; //文件路径名
                string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1); //附件名称
                // string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);        //图片格式
                string path = HttpContext.Current.Request.MapPath("~/HT/useImg/");//获取上传文件的网站目录路径
                this.FUP.SaveAs(path + fileName);//存储文件到磁盘
                htUrl = "~/HT/useImg/" + fileName;
                this.lblhtfj.Text = fileName;
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key003", "<script>alert('附件上传成功!');</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),"key02","<script>alert('必须指定文件!');</script>");
            }
      

  3.   


    if (this.FUP.HasFile)//检查是否有文件
            {
                string fullFileName = this.FUP.PostedFile.FileName;                           //文件路径名
                string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);   //附件名称
                // string type = fullFileName.Substring(fullFileName.LastIndexOf(".") + 1);        //图片格式
                string path = HttpContext.Current.Request.MapPath("~/HT/useImg/");//获取上传文件的网站目录路径
                this.FUP.SaveAs(path + fileName);//存储文件到磁盘
                htUrl = "~/HT/useImg/" + fileName;
                this.lblhtfj.Text = fileName;
                Page.ClientScript.RegisterStartupScript(this.GetType(), "key003", "<script>alert('附件上传成功!');</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(),"key02","<script>alert('必须指定文件!');</script>");
            }