日期:2014-05-17  浏览次数:20340 次

求简单的ASP.NET下载代码
谁有,发个过来啊,要任何客户端txt都能够下载的

------解决方案--------------------
        /// <summary>
        /// 下载文件
        /// </summary>
        protected void Down_Click(object sender, EventArgs e)
        {
            //获取id集合
            string ids = Utils.GetRequest("cbItem");
            if (ids == string.Empty)
            {
                return;//未选择任何文件
            }
            List<int> list = Utils.Getids(ids);
            FileBLL filebll = new FileBLL();
            //下载选中文件
            foreach (int id in list)
            {
                Down(filebll.GetFile(id).FileAddr);
            }
        }
------解决方案--------------------
if (File.Exists(fileName))
            {
                Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                long num3 = stream.Length - 1L;
                HttpContext.Current.Response.AddHeader("Content-Range", "bytes 0-" + num3.ToString() + "/" + stream.Length.ToString());
                HttpContext.Current.Response.AddHeader("Content-Length", stream.Length.ToString());
                if (!isPreview)
                {
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + displayName);
                }
        &nbs