码迷,mamicode.com
首页 > 其他好文 > 详细

下载Word文档

时间:2017-05-31 12:04:53      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:inf   length   log   path   response   end   ade   stream   new   

//方法一 下载word
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string s = Server.MapPath(WordPath);
Response.WriteFile(WordPath);
//Response.Write(s);
Response.Flush();
Response.Close();

//方法二 下载word
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "Application/msword";
string strFilePath = "";
//strFilePath = Server.MapPath(WordPath);
//strFilePath = "\\\\172.8.8.8\\TEST.doc";
strFilePath = WordPath;
FileStream fs = new FileStream(strFilePath, FileMode.OpenOrCreate, FileAccess.Read);
Response.WriteFile(strFilePath, 0, fs.Length);
fs.Close(); 

//方法三 下载word
string path = Server.MapPath("//172.8.8.8/TEST.doc");
path = WordPath;
FileInfo file = new FileInfo(path);
FileStream myfileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
byte[] filedata = new Byte[file.Length];
myfileStream.Read(filedata, 0, (int)(file.Length));
myfileStream.Close();
Response.Clear();
Response.ContentType = "application/msword";
Response.AddHeader("Content-Disposition", "attachment;filename=file.doc");
Response.Flush();
Response.BinaryWrite(filedata);
Response.End(); 

 

下载Word文档

标签:inf   length   log   path   response   end   ade   stream   new   

原文地址:http://www.cnblogs.com/blossomwei/p/6922991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!