下载Word文档

Posted 菜鸟程序猿

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了下载Word文档相关的知识,希望对你有一定的参考价值。

//方法一 下载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文档的主要内容,如果未能解决你的问题,请参考以下文章

如何在 MS Word 文档中显示代码片段,因为它在 *** 中显示(滚动条和灰色背景)

从搜索文档中查找最小片段的算法?

以编程方式在Word文档中布局图像

试图从 azure blob 下载 word 文档

JAVA导出下载word文档(导出带富文本图片word)

如何在网上直接打开word文档,不用下载