Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

i want to develop asp application that view the any office document
and i used
C#
Response.ContentType
to display the document

and this is the code
C#
if (URL.Contains(".doc"))//URL is document path
                  Response.ContentType = "application/msword";
        Response.WriteFile(URL);
        Response.Flush();
        Response.Close();


but when i run , display a downloaded dialog and didn't view any thing

the MIMI list

http://blogs.msdn.com/b/vsofficedeveloper/archive/2008/05/08/office-2007-open-xml-mime-types.aspx
[^]

any idea to display document in browser , i need it necessary

Thx
Posted

1 solution

You cannot display doc file in browser without saving it, if you want then you have to write plugin with respect to each browser and that is a very length code of work. A PDF can be opened in a browser, if you can convert doc to pdf that could be an easy solution.
Good luck
 
Share this answer
 
Comments
Darsh_Basha 27-Feb-13 10:06am    
Hi
@Anuja Pawar Indore

thx for replay , but your idea is not good

i want to use
Collapse | Copy Code
Response.ContentType = "application/msword";
and why convert the document to pdf

thx
Anuja Pawar Indore 27-Feb-13 10:11am    
Its not converting to PDF, but pdf can be opened in browser.
have a look at this
http://stackoverflow.com/questions/2519026/how-do-you-stream-an-excel-2007-or-word-2007-file-using-asp-net-and-c-sharp
bbirajdar 27-Feb-13 12:28pm    
I agree with Anuja..Browsers do not natively support office documents. If you think the answer is wrong then show us a website which opens them in browser. And to add to the answer, most browsers do not support PDF too..You need to read doc contents and display them in HTML +5
Darsh_Basha 28-Feb-13 3:43am    
Hi
@Anuja Pawar Indore
@Anuja Pawar Indore
using Microsoft.Office.Interop.Word;// Microsoft.Office.Interop.Word reference

private void readFileContent(string path )

{

ApplicationClass wordApp = new ApplicationClass();

object file = path;

object nullobj = System.Reflection.Missing.Value;
object format = true;

Microsoft.Office.Interop.Word.Document doc =wordApp.Documents.Open(

ref file,
ref nullobj,
ref nullobj,

ref nullobj,
ref nullobj,
ref nullobj,

ref nullobj,
ref nullobj,
ref nullobj,

ref format,
ref nullobj,
ref nullobj,
ref nullobj,
ref nullobj,
ref nullobj,
ref nullobj);



doc.ActiveWindow.Selection.WholeStory();

doc.ActiveWindow.Selection.Copy();

string sFileText = doc.Content.Text;
string style = doc.

doc.Close(ref nullobj, ref nullobj, ref nullobj);

wordApp.Quit(ref nullobj, ref nullobj, ref nullobj);

Response.Write(word);

}

this function open the content of the word file in web,but without word style
thx
Anuja Pawar Indore 28-Feb-13 8:50am    
The above code opens and fill a Word file from File System, if this is what you need, then good

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