在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
方法一:以二进制流的形式下载 string fileName = this.nameSave.Value;//客户端保存的文件名 //以字符流的形式下载文件 FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; //通知浏览器下载文件而不是打开 Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes);//将流写到回发报文中 Response.Flush(); Response.End();//关闭缓冲区,将报文回立即回发给客户端 方法二:直接输出文件 string FileName = "文件名.xls"; Response.Clear(); Response.Buffer = true; EnableViewState = false; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8)); Response.WriteFile(FileName); Response.Flush(); Response.Close(); Response.End();
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论