用fileupload控件做一个上传下载的功能
我现在要把上传的文件保存到数据库中,这该怎么保存呢?
而且要怎么获取fileupload控件中的文件路径呢?

解决方案 »

  1.   

    你保存在数据库的是文件的路径 
    文件上传在项目的文件夹里面if (this.getlink.FileName != "")
                {
                    string fileaddress = getlink.FileName.Substring(getlink.FileName.LastIndexOf("."));
                    string filename = DateTime.Now.ToString("yyyyMMddhhmmssms") + fileaddress;
                    string filepath = Server.MapPath("~/themes/upload") + "/" + filename;
                    getlink.SaveAs(filepath);
                }
      

  2.   

    protected void btnUpload_Click(object sender, EventArgs e)  
      {  
      //判断是否上传了文件  
      if (fileUpload.HasFile)  
      {  
      string savePath = Server.MapPath("~/upload/");  
      if(!System.IO.Directory.Exists(savePath))  
      {  
      System.IO.Directory.CreateDirectory(savePath);  
      }  
      savePath = savePath + "\\" + fileUpload.FileName;  
      fileUpload.SaveAs(savePath);//保存文件  
      foreach(string s in File.ReadAllLines(savePath))
      {
      //操作数据库sqlhelper
      }
      }  
      }  读取文件内容file.readallbytes
      

  3.   


    无语了  
    http://www.javaeye.com/topic/383302
    你保存路径到数据库
     string fileaddress = getlink.FileName.Substring(getlink.FileName.LastIndexOf("."));
     string filename = DateTime.Now.ToString("yyyyMMddhhmmssms") + fileaddress;//重命名
     string filepath = Server.MapPath("~/themes/upload") + "/" + filename;//保存的路径
     getlink.SaveAs(filepath);文件上传保存到服务器指定文件夹