Click here to Skip to main content
15,886,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I want to read word document with the formats (font color,font size) and dispaly in a aspx page. I am using below code to read the word file. I am able to display the text in word document but i want to display in same format. Please help me to come out of it.



C#
Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();

FileUpload1.SaveAs(Server.MapPath(FileUpload1.FileName));
object objFile = Server.MapPath(FileUpload1.FileName);
object objNull = System.Reflection.Missing.Value;
object objReadOnly = true;

//Open Document
Microsoft.Office.Interop.Word.Document Doc
    = AC.Documents.Open(ref objFile, ref objNull,
                             ref objReadOnly, ref objNull,
                             ref objNull, ref objNull, ref objNull,
                             ref objNull, ref objNull, ref objNull,
                             ref objNull, ref objNull, ref objNull,
                             ref objNull, ref objNull, ref objNull);

int i = 1;

foreach (Microsoft.Office.Interop.Word.Paragraph objParagraph
         in Doc.Paragraphs)
{
    try
    {
        TextBox1.Text += Doc.Paragraphs[i].Range.Text;
    }
    catch (Exception ex)
    {
        throw ex;
    }
    i++;
}

AC.Quit(ref objNull, ref objNull, ref objNull);


Thanks in advance.
Posted
Updated 6-Feb-14 20:11pm
v2

Refer - Embedding word document in web form[^].
Quote:
If all the clients that are browsing the site are going to have Word installed and use Internet Explorer, you could embed it with an ActiveX object[^]. If these requirements are not met you might need to convert it to some more standard format that a browser is capable of displaying such as a jpeg image. You may also look at this option[^].
 
Share this answer
 
Hi,

Thanks for the solutions,

To display the content with same format. I used this[^] to convert the word document to Html and simply displayed html page in Iframe.
 
Share this answer
 

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