超链接如何下载文件txt,word,excel等等

首先建立一个超链接<a href=\"DownloadFile.aspx?fileid=" + dr["fileid"].ToString() + "&filename=" + dr["filename"] + "\">其中超链接href转到Download.aspx,接着,在DownloadFile.aspx页面中使用

string fileid = Request.QueryString["fileid"];
            string filename = Request.QueryString["filename"];
            string filepathname = Server.MapPath(@"~/upload/") + fileid;
            Response.Clear();
            Response.ClearHeaders();
            Response.Buffer = false;
            Response.ContentType = "application/octet-stream";
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8));
            Response.WriteFile(filepathname);
            Response.Flush();
            Response.End();

直接实现页面文件的下载

posted @ 2013-07-29 11:38  returnKing  阅读(1731)  评论(0编辑  收藏  举报