首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

.net中上载文件的方法 WriteFile实现上载

2012-12-25 
.net中下载文件的方法 WriteFile实现下载protected void Button2_Click(object sender, EventArgs e){stri

.net中下载文件的方法 WriteFile实现下载

protected void Button2_Click(object sender, EventArgs e)        {            string fileName = "chracater14.jpg";//客户端保存的文件名            string filePath = Server.MapPath("../../images/chracater14.jpg");//路径            FileInfo fileInfo = new FileInfo(filePath);            Response.Clear();            Response.ClearContent();            Response.ClearHeaders();            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);            Response.AddHeader("Content-Length", fileInfo.Length.ToString());            Response.AddHeader("Content-Transfer-Encoding", "binary");            Response.ContentType = "application/octet-stream";            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");            Response.WriteFile(fileInfo.FullName);            Response.Flush();            Response.End();        }

?感谢网友http://apps.hi.baidu.com/share/detail/24298464

热点排行