Click here to Skip to main content
16,018,496 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

i have function that read the content of the word file and display it in the web page
but without the format or word style like :
1. pictures
2. tables
3. bullets ,etc...

the function
C#
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(sFileText);

 }


any idea to open a document with here style

Thx
Posted
Comments
bbirajdar 28-Feb-13 4:05am    
Your question has already been answered here http://www.codeproject.com/Questions/553722/Howplustoplusviewplusofficeplusdocumentplusthrough ..Why post the duplicates?
Darsh_Basha 28-Feb-13 5:07am    
Hi @aspnet_regiis
no answer, where is it
i have some problems with this code and ask for Help

1 solution

Hi,

Try this Code...

FileInfo file = new FileInfo("Your FilePath");
Response.ClearContent();
Response.AddHeader("Content-Disposition", "inline;filename=" + file.Name);
Respone.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/msword";
Reponse.TransmitFile(file.FullName);
Response.End();
 
Share this answer
 
Comments
Darsh_Basha 28-Feb-13 5:50am    
Thx Ibrahim Uylas

but this didn't display the document in a webpage ,but display download window

i want to display the document in web with same style
Ibrahim Uylas 28-Feb-13 6:41am    
I think you may try to conversion word to html file. And you have a html code. Then you may display it in your page.
Darsh_Basha 28-Feb-13 7:26am    
Ibrahim Uylas

tell me how
and think it's not good idea
Ibrahim Uylas 28-Feb-13 7:44am    
Darsh_Basha

Please check the links below, it provides the code sample of converting Word .doc files to .html
http://www.wherecanibuyit.co.uk/ASP/converting_word_doc_files_to_html.html

http://www.c-sharpcorner.com/UploadFile/munnamax/WordToHtml03252007065157AM/WordToHtml.aspx

Also you can download the Doc to HTML Converter from:
http://www.modeltext.com/word/index.aspx

Furthermore, a thread about "Convert from Word to HTML"
http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/1ce972ab-8a88-4962-a2fd-482c9210718c

I Hope they are helpful!
Darsh_Basha 28-Feb-13 8:23am    
Ibrahim Uylas

i didn't like to do this , more complex and waste time for convert word to html and display it

i ask u
i i do this what is the view of the document the same like in the word

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