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

建设b2b网站要求百度收录入口在哪里查询

建设b2b网站要求,百度收录入口在哪里查询,网站还没上线 可以对网站备案吗,泰安疫情最新消息原文地址为: C#实现文件下载 1,Http 协议中有专门的指令来告知浏览器, 本次响应的是一个需要下载的文件. 格式如下:Content-Disposition: attachment;filenamefilename.ext以上指令即标记此次响应流是附件,且附件文件名为 filename.ext注意:…
原文地址为: C#实现文件下载

1,Http 协议中有专门的指令来告知浏览器, 本次响应的是一个需要下载的文件. 格式如下:
Content-Disposition: attachment;filename=filename.ext
以上指令即标记此次响应流是附件,且附件文件名为 filename.ext
注意:
(1): 中文文件名需要进行URLEncode编码, 否则在IE 6 下会提示是”无法识别的文件”.

但经实际测试,在Chrome下不进行URLEncode编码, 也能正常显示.

(2): 文件名不能有空格, 否则也会被认为是”无法识别的文件”.

(3): [ASP.Net中] 向响应流中添加该指令必须使用 response.AddHeader() 函数; 使用

response.Header.Add() 则会报错.

下面是一个实现下载文件功能的函数:

       /// <summary>/// 使用微软的TransmitFile下载文件/// </summary>/// <param name="filePath">服务器相对路径</param>public 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;filename=filename.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 name="filePath">相对路径</param>public 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 name="filePath"></param>public 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.khdw.cn/news/67628.html

相关文章:

  • 程序员 做网站 微信公众号 赚钱微商推广哪家好
  • wp做购物网站小游戏推广接单平台
  • 做网站公司松江google推广及广告优缺点
  • 昆山企业网站建设公司百度云搜索入口
  • 如何免费网站建设搜索引擎优化趋势
  • web美食网站设计与开发网址信息查询
  • 网站开发云南电商营销推广有哪些?
  • 小朋友做安全教育的网站百度游戏排行榜风云榜
  • 无锡工程建设监察支队网站cnzz数据统计
  • 东莞建筑公司seo优化案例
  • 上海市建设网站站长之家素材网站
  • wordpress内容模版文件在哪个目录站内优化
  • 公司网站设计收费拉新注册app拿佣金
  • 精品课程网站设计百度投诉中心人工电话
  • 网站开发接单营销推广有哪些形式
  • 修改wordpress首页缩略图尺寸惠州seo公司
  • 湖南网页设计培训网站建设搜索引擎优化的名词解释
  • 大连做网站优化哪家好本地广告推广平台哪个好
  • wordpress统计类插件关键词优化推广公司哪家好
  • 一个学校怎么制作网站企业网站设计
  • 镇江网站建设推广查数据的网站有哪些
  • 黄冈公司网站推广软件首选永久免费建个人网站
  • pc网站做成移动网站发稿网
  • 做 爱 网站小视频在线观看百度收录查询
  • 自适应网站建站他达拉非功效与作用主要会有哪些
  • 政府网站建设合同优化电池充电什么意思
  • 搜索引擎搜不到网站苏州疫情最新情况
  • 做网站需要看啥书牛推网络
  • 西渡网站建设代推广app下载
  • 做移动网站中央电视台新闻联播