如何在浏览器中打开Word文件 [英] How to open a word file in browser

查看:134
本文介绍了如何在浏览器中打开Word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想在浏览器中打开Word文件..我尝试了以下代码..
它正在下载文件..我要在浏览器中打开Word文件....

为此要做什么

我的代码如下:

hi all

i want to open word file in the browser.. i tried following code..
its downloading the file..i want to open word file in the browser....

what to do for that

my code is as below:

protected void bl_procedures_Click(object sender, BulletedListEventArgs e)
   {

       try
           {
               string path = Server.MapPath("PROCEDURES/" + bl_procedures.Items[e.Index].Text);
               System.IO.FileInfo file = new System.IO.FileInfo(path);
               Response.Clear();
               Response.AddHeader("Content-Disposition", "inline; filename=" + file.Name);
               Response.AddHeader("content-length", file.Length.ToString());
               Response.ContentType = ReturnExtension(file.Length.ToString());
           Response.TransmitFile(file.FullName);
               //Response.WriteFile(file.FullName);
               Response.End();
           }
           catch(Exception ex)
           {
               Label2.Text = ex.ToString();
           }

   }
   private string ReturnExtension(string fileExtension)
   {
       switch (fileExtension)
       {
           case ".htm":
           case ".html":
           case ".log":
               return "text/HTML";
           case ".txt":
               return "text/plain";
           case ".doc":
               return "application/ms-word";
           case ".tiff":
           case ".tif":
               return "image/tiff";
           case ".asf":
               return "video/x-ms-asf";
           case ".avi":
               return "video/avi";
           case ".zip":
               return "application/zip";
           case ".xls":
           case ".csv":
               return "application/vnd.ms-excel";
           case ".gif":
               return "image/gif";
           case ".jpg":
           case "jpeg":
               return "image/jpeg";
           case ".bmp":
               return "image/bmp";
           case ".wav":
               return "audio/wav";
           case ".mp3":
               return "audio/mpeg3";
           case ".mpg":
           case "mpeg":
               return "video/mpeg";
           case ".rtf":
               return "application/rtf";
           case ".asp":
               return "text/asp";
           case ".pdf":
               return "application/pdf";
           case ".fdf":
               return "application/vnd.fdf";
           case ".ppt":
               return "application/mspowerpoint";
           case ".dwg":
               return "image/vnd.dwg";
           case ".msg":
               return "application/msoutlook";
           case ".xml":
           case ".sdxl":
               return "application/xml";
           case ".xdp":
               return "application/vnd.adobe.xdp+xml";
           default:
               return "application/octet-stream";
       }



}

谁能帮我提供在浏览器中查看Word文件的代码...


在此先感谢



}

can any one help me with the code for viewing the word file in browser...


thanks in advance

推荐答案


如何在asp.net中打开现有Word文件 [ ^ ]


此处 [ ^ ]是您的链接.
Here[^] is the link for you.


这篇关于如何在浏览器中打开Word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆