Click here to Skip to main content
15,889,865 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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";
       }


}

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


thanks in advance
Posted
Comments
Amir Mahfoozi 3-Jan-12 9:37am    
I'm curious to know that is there any web site that return a word document to its clients and they open the word document in their browsers ?
Please see this page : http://en.wikipedia.org/wiki/Mime_type

 
Share this answer
 
Comments
Ragi Gopi 3-Jan-12 2:28am    
its showing the file ...but the content is like as beloww

��ࡱ�>�� {}����z���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������[� ��)bjbj���� 4�ΐΐ)���������+++++����???? K�?w:?????�������$��S@+++??�1222�+?+?�2�222?����P�v}���? 2�G0w2��2�+2�2( w���������������������������������������������������������������������� �: Purchase of Equipments: PROCEDURES OriginatorsForwarding throughStepsIndividuals/ CommitteesActions by Individuals/CommitteesScientistHOD1OriginatorsRequest for the equipmentHODPC2Equipment CommitteeEvaluates the requestPCEvaluates the availability of fundsSIC-CIUEvaluates necessity of the equipmentEnggPrepares the MinutesDirector3Chairman, Equipment CommitteeForwards the Minutes to Sr. Supdt. (Purchase)Dy. Regr (Admn)Registrar4Sr. Supdt. (Purch)Invites QuotationsDy. Regr (Accts)RegistrarMakes comparative tablesRegistrarForwards Quotations to Equipment CommitteeSr. Supdt. (Admn)Dy. Regr (Admn)5Equipment CommitteeExamines the QuotationsSr. Supdt. (Accts)Dy. Regr (Accts)Shortlists the QuotationsSr. Supdt. (Purch)Sr. Supdt. (Admn)Prepares MinutesSr. Supdt. (Stores)Sr. Supdt. (Admn)6Chair, Equipment CommitteeForwards the Quotations to Purchase CommitteeSr. Supdt. (Vehic)Sr. Supdt. (Admn)Forwards the Minutes to Purchase Committee7Purchase CommitteeEvaluates the Minutes of the Equipment CommitteeNegotiates with the FirmsProvides Recommendations to the Director8DirectorDisagrees to purchase the equipment, orAgrees to purchase the equipment9Sr. Supdt (Purch)File transferred to Sr. Supdt (Purchase)Initiates Purchase ProceedsOpens LCReceives the EquipmentTransfers the Equipment to Sr. Supdt (Stores)Communicates the price to Sr. Supdt. (Accts)10Sr. Supdt. (Accts)Debits the price to the project or to appropriate heads11Sr. Supdt (Stores)Takes stock of the EquipmentConveys the arrival of the Equipment to the Originator12OriginatorProvides indent for issue of the Equipment 13Sr. Supdt (Stores)Issues the Equipment to the Originator  $%EI�()����ǷǨ�h�E�h�v�CJOJQJaJh�E�h�K5�CJOJQJaJh�E�h�v�5�CJOJQJaJhr5�#h�E�h�*�5�CJOJQJ^JaJ#h�E�hr5�5�CJOJQJ^JaJ #$%1<DJb����������Ekd$$IfT�l�����" t��6���������4�4� la�h�yt�E��T$$Ifa$gd�E�l� ��%�kdS$$If�l��r|�oc ' x(#p� � t���������������0��������+6�������������������������4�4� la���p�������������yt�E������������$Ifgd�PMl� $$Ifa$gd�E�l� $Ifgd�v�l� $IfgdTx�l� ��%�kdp$$If�l��r|�oc ' x(#p� � t���������������0��������+6�������������������������4�4� la���p�������������yt�E������������$Ifgd9h�l� $Ifgd�PMl� $$Ifa$gd�E�l� $Ifgd�v�l� $IfgdTx�l� ��%�kd�$$If�l��r|�oc ' x(#p� � t���������������0��������+6�������������������������4�4� la���p�������������yt�E������ �����$Ifgd9h�l� $Ifgd�
Pankaj Chamria 3-Jan-12 10:03am    
Questions -
1. Is word installed on your machine?
2. Is this output showing up in browser window itself or notepad? It surely is not showing up in word which means either you do not have MS word installed or your Response.Write code to output this file is not correct.
Ragi Gopi 4-Jan-12 4:01am    
1)ms office 2007 is installed in my system..
2output is showing in browser window itself......
and my code to display file is above in my question..
 
Share this answer
 
Comments
Ragi Gopi 3-Jan-12 3:29am    
Sorry not working
Ragi Gopi 4-Jan-12 4:37am    
can we open file as google docs do?????
did any one know about it.
Here[^] is the link for you.
 
Share this answer
 
Comments
Rajesh Anuhya 4-Jan-12 4:32am    
How it is Downvoted?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900