从服务器端下载文件

string path = @"../../TemplateForDownload/AddressBook.xls";
        
        if (File.Exists(Server.MapPath(path)))
        {
            //ExportFilePath = fileName;
            //string _RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath).ToLower();//当前的绝对路径 

            Response.ContentType = "application/ms-excel;charset=UTF-8";
            
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("通讯录模板.xls"));//解决中文乱码
            string filename = Server.MapPath(path);
            Response.TransmitFile(path);
        }
View Code

 

posted @ 2014-12-03 15:37  一个码农的成长之路  阅读(99)  评论(0编辑  收藏  举报