本帖最后由 wusahaoshuai 于 2011-07-23 20:45:30 编辑

解决方案 »

  1.   

    http://dotnet.aspx.cc/file/Upload-Image-To-Access-With-C-Sharp-And-VB.NET.aspx
      

  2.   

    ASP.NET上传文件到数据库
      

  3.   

    对应这个里面http://dotnet.aspx.cc/file/Upload-Image-To-Access-With-C-Sharp-And-VB.NET.aspx 的代码,aspx代码那部分,数据库应该怎么建???
      

  4.   

    数据库
    http://dotnet.aspx.cc/Exam/Image2Access.zip
      

  5.   

    如果换成sql server 数据库,那么数据库应该怎么建立,代码怎么改动??
      

  6.   

    文件字段选择Image类型,其他字段自己需要选择
      

  7.   

    <body> 
        <form id="form1" runat="server"> 
        <div> 
        <table style="width: 343px"> 
                <tr> 
                    <td style="width: 100px"> 
                        多文件上传</td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:FileUpload ID="FileUpload1" runat="server" Width="475px" /> 
                        </td> 
                    <td style="width: 100px"> 
                        </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:FileUpload ID="FileUpload2" runat="server" Width="475px" /></td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:FileUpload ID="FileUpload3" runat="server" Width="475px" /></td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
                <tr> 
                    <td style="width: 100px"> 
                        <asp:Button ID="bt_upload" runat="server" OnClick="bt_upload_Click" Text="一起上传" /> 
                        <asp:Label ID="lb_info" runat="server" ForeColor="Red" Width="448px"></asp:Label></td> 
                    <td style="width: 100px"> 
                    </td> 
                </tr> 
            </table> 
        </div> 
        </form> 
    </body>
    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page  

        protected void Page_Load(object sender, EventArgs e) 
        {     } 
        protected void bt_upload_Click(object sender, EventArgs e) 
        { 
            if (FileUpload1.PostedFile.FileName == "" && FileUpload2.PostedFile.FileName == "" && FileUpload3.PostedFile.FileName == "") 
            { 
                this.lb_info.Text = "请选择文件!"; 
            } 
            else 
            { 
                HttpFileCollection myfiles = Request.Files; 
                for (int i = 0; i < myfiles.Count; i++) 
                { 
                    HttpPostedFile mypost = myfiles[i]; 
                    try 
                    { 
                        if (mypost.ContentLength > 0) 
                        { 
                            string filepath = mypost.FileName;//C:\Documents and Settings\Administrator\My Documents\My Pictures\20022775_m.jpg 
                            string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);//20022775_m.jpg 
                            string serverpath = Server.MapPath("~/images/") + filename;//C:\Inetpub\wwwroot\WebSite2\images\20022775_m.jpg 
                            mypost.SaveAs(serverpath); 
                            this.lb_info.Text = "上传成功!"; 
                        } 
                    } 
                    catch (Exception ex) 
                    { 
                        this.lb_info.Text = "上传发生错误!原因:" + ex.Message.ToString(); 
                    } 
                } 
            } 
        } 
    }jquery 批量上传插件Uploadify
    参考
      

  8.   

    #region 文件下载
           public bool DownLoadFile(string localPath, string hostURL, int byteCount, string userID, long cruuent)
           {
               
               bool result = true;
               
               
               string tmpURL = hostURL;
              
               byteCount = byteCount * 1024;
               hostURL = tmpURL + "&npos=" + cruuent.ToString();
               
               System.IO.FileStream fs;  
               fs = new FileStream(localPath, FileMode.OpenOrCreate);
               if (cruuent > 0)
               {
                   //偏移指针
                   fs.Seek(cruuent, System.IO.SeekOrigin.Current); 
               }
               System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(hostURL);
               if (cruuent > 0)
               {
                   request.AddRange(Convert.ToInt32(cruuent));    //设置Range值
               }           try
               {
                   //向服务器请求,获得服务器回应数据流
                   System.IO.Stream ns = request.GetResponse().GetResponseStream();               byte[] nbytes = new byte[byteCount];
                   int nReadSize = 0;
                   nReadSize = ns.Read(nbytes, 0, byteCount);
                  
                   while (nReadSize > 0)
                   {
                       fs.Write(nbytes, 0, nReadSize);
                       nReadSize = ns.Read(nbytes, 0, byteCount);
                      
                   }
                   fs.Close();
                   ns.Close();
               }
               catch(Exception ex)
               {
                   LOG.Error("下载" + localPath + "的时候失败!" + "原因是:" + ex.Message);
                   fs.Close();
                   result = false;
               }
               return result;     
           }
           #endregion 
      

  9.   

    SqlConnection cn = new SqlConnection();//数据库链接 
            cn.Open();
            SqlDataAdapter da2 = new SqlDataAdapter("select   *   from   myfile   where   id=   24 ", cn);//读出数据库中相应的数据 
            DataSet ds2 = new DataSet();
            da2.Fill(ds2);
            byte[] b2 = (byte[])ds2.Tables[0].Rows[0]["files "];
            string type = (string)ds2.Tables[0].Rows[0]["type "];
            Response.Clear();
            string Type = checktype(type);
            Response.AddHeader("Content-Disposition", "attachment; filename=下载" + type);
            Response.AddHeader("Content-Length ", b2.Length.ToString());
            Response.ContentType = Type;
            Response.BinaryWrite(b2);
            Response.End();        string FileName = ((LinkButton)sender).CommandArgument; 
            Response.Clear();
            Response.ContentType = Type;
            Response.AddHeader("Content-Disposition", "attachment;FileName= " + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
            Response.WriteFile(FileName);
            Response.End();
      

  10.   

    回复13楼,用你的代码,提示:
    CS0103: 当前上下文中不存在名称“checktype”还有
    Response.AddHeader("Content-Disposition", "attachment; filename=下载" + type);
    中的filename 怎么来的,需要自己定义吗??