简单问题:在ASPX页面,放一按钮,点该按钮,实现文件下载,请问如何实现(保存在本地,要求弹出保存框),
网页要求屏蔽右健,如何实现,谢谢是web,不是winform

解决方案 »

  1.   

    web的话放个链接,地址指向文件不就可以了
      

  2.   

            string pathfile = @"D:\1.txt";//文件路径
            FileStream fs = new FileStream(pathfile, FileMode.Open, FileAccess.Read);
            long p = 0;
            FileInfo fi = new FileInfo(pathfile);
            long l = fi.Length;
            if (Request.Headers["Range"] != null)
            {
                Response.StatusCode = 206;
                p = long.Parse(Request.Headers["Range"].Replace("bytes=", "").Replace("-", ""));
            }        Response.AddHeader("Content-Length", ((long)(l - p)).ToString());
            if (p != 0)
            {
                Response.AddHeader("Content-Range", "bytes " + p.ToString() + "-" + ((long)(l - p)).ToString() + "/" + l.ToString());
            }        Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fi.Name));
            fs.Position = p;        int i = 1;
            byte[] b = new Byte[1024];
            while (i > 0)
            {
                i = fs.Read(b, 0, b.Length);
                Response.OutputStream.Write(b, 0, i);
            }        fs.Close();
            Response.End();
      

  3.   

    页面代码:
    <script type="text/javascript">
                function download()
                {
                    window.open('http://xxxxx.xxx/xxx.xxx');
                }
            </script>
            <asp:Button ID="Button1" runat="server" Text="下载" OnClientClick="download()" OnClick="Button1_Click" />
    后台代码:
    protected void Button1_Click(object sender, EventArgs e)
    {
    //统计代码
    }