当前位置: 首页 > news >正文

免费个人网站服务器自助外贸网站建设

免费个人网站服务器,自助外贸网站建设,wordpress拒绝服务,国外租用服务器的平台原文地址为#xff1a; C#实现文件下载 1#xff0c;Http 协议中有专门的指令来告知浏览器, 本次响应的是一个需要下载的文件. 格式如下:Content-Disposition: attachment;filenamefilename.ext以上指令即标记此次响应流是附件,且附件文件名为 filename.ext注意#xff1a;…原文地址为 C#实现文件下载 1Http 协议中有专门的指令来告知浏览器, 本次响应的是一个需要下载的文件. 格式如下:Content-Disposition: attachment;filenamefilename.ext以上指令即标记此次响应流是附件,且附件文件名为 filename.ext注意(1): 中文文件名需要进行URLEncode编码, 否则在IE 6 下会提示是”无法识别的文件”.但经实际测试,在Chrome下不进行URLEncode编码, 也能正常显示.(2): 文件名不能有空格, 否则也会被认为是”无法识别的文件”.(3): [ASP.Net中] 向响应流中添加该指令必须使用 response.AddHeader() 函数; 使用response.Header.Add() 则会报错.下面是一个实现下载文件功能的函数 /// summary/// 使用微软的TransmitFile下载文件/// /summary/// param namefilePath服务器相对路径/parampublic void TransmitFile(string filePath){try{filePath Server.MapPath(filePath);if (File.Exists(filePath)){FileInfo info new FileInfo(filePath);long fileSize info.Length;HttpContext.Current.Response.Clear(); //指定Http Mime格式为压缩包HttpContext.Current.Response.ContentType application/x-zip-compressed;// Http 协议中有专门的指令来告知浏览器, 本次响应的是一个需要下载的文件. 格式如下:// Content-Disposition: attachment;filenamefilename.txtHttpContext.Current.Response.AddHeader(Content-Disposition, attachment;filename Server.UrlEncode(info.FullName));//不指明Content-Length用Flush的话不会显示下载进度 HttpContext.Current.Response.AddHeader(Content-Length, fileSize.ToString());HttpContext.Current.Response.TransmitFile(filePath, 0, fileSize);HttpContext.Current.Response.Flush();}}catch{ }finally{HttpContext.Current.Response.Close();}} 2 下面是使用WriteFile实现下载 /// summary/// 使用WriteFile下载文件 /// /summary/// param namefilePath相对路径/parampublic void WriteFile(string filePath){try{filePath Server.MapPath(filePath);if (File.Exists(filePath)){FileInfo info new FileInfo(filePath);long fileSize info.Length;HttpContext.Current.Response.Clear();HttpContext.Current.Response.ContentType application/octet-stream;HttpContext.Current.Response.AddHeader(Content-Disposition, attachement;filename Server.UrlEncode(info.FullName));//指定文件大小 HttpContext.Current.Response.AddHeader(Content-Length, fileSize.ToString());HttpContext.Current.Response.WriteFile(filePath, 0, fileSize);HttpContext.Current.Response.Flush();}}catch{ }finally{HttpContext.Current.Response.Close();}} 3下面是分块实现下载 /// summary/// 使用OutputStream.Write分块下载文件 /// /summary/// param namefilePath/parampublic void WriteFileBlock(string filePath){filePath Server.MapPath(filePath);if (!File.Exists(filePath)){return;}FileInfo info new FileInfo(filePath);//指定块大小 long chunkSize 4096;//建立一个4K的缓冲区 byte[] buffer new byte[chunkSize];//剩余的字节数 long dataToRead 0;FileStream stream null;try{//打开文件 stream new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);dataToRead stream.Length;//添加Http头 HttpContext.Current.Response.ContentType application/octet-stream;HttpContext.Current.Response.AddHeader(Content-Disposition, attachement;filename Server.UrlEncode(info.FullName));HttpContext.Current.Response.AddHeader(Content-Length, dataToRead.ToString());while (dataToRead 0){if (HttpContext.Current.Response.IsClientConnected){int length stream.Read(buffer, 0, Convert.ToInt32(chunkSize));HttpContext.Current.Response.OutputStream.Write(buffer, 0, length);HttpContext.Current.Response.Flush();HttpContext.Current.Response.Clear();dataToRead - length;}else{//防止client失去连接 dataToRead -1;}}}catch (Exception ex){HttpContext.Current.Response.Write(Error: ex.Message);}finally{if (stream ! null){stream.Close();}HttpContext.Current.Response.Close();}} 转载请注明本文地址 C#实现文件下载
http://www.hkea.cn/news/14267902/

相关文章:

  • 网站建设尾款收取企业网站美工设计
  • 做网站要花钱吗校园网站建设意义
  • 建设银行网站功能介绍网站推广由什么样的人来做
  • 注册做网站的公司手机网站flash
  • 网站美工设计收费怎么样可以做自己的网站
  • 乐陵森林覆盖率wordpress网站优化
  • 教育网站集约化建设移动网站建站系统下载
  • 惠州建设局官方网站体育彩票网站开发该做哪些步骤
  • 2014网站设计趋势百度推广代理公司
  • 哪些网站可以做代理徐州制作网站软件
  • 可以注册的网站建立网站买空间哪家好
  • 网站登记表发软文是什么意思
  • 大型网站建设多少钱在线做GO分析的网站
  • 网站优化外链做钓鱼网站判刑
  • 网站排名seo培训长沙中小企业做网站
  • 龙岩网站推广软件免费logo生成器有哪些
  • 网站开发毕业设计源码建网站一般需要多少钱
  • 怎么销售网站建设兼职网站项目建设报告
  • 网站开发的常用流程珠海关键词优化收费
  • 保定网站制作企业建模师的就业前景
  • 网站建设平台还有没有趋势南京一站式工程装饰装修网站
  • 网站添加漂浮二维码怎么做唐山最新消息今天
  • 去泰国做网站发网站孵化基地网站怎么建设
  • 目前主流的网站开发语言做一个代驾app需要多少钱
  • 门户型网站都有哪些北京市新闻
  • 网站的标题可以改吗百度关键词排名怎么做
  • 免费的推广网站有哪些网站建设基本完成
  • 百度怎么验证网站深圳企业网查询
  • 辽宁建设工程造价管理网站字体在线生成器
  • 个人购物网站备案wordpress博客分类