0

I want to read the msword (.doc/.docx) file whole content which having images, styles, text everything in asp .net using c#.

I used to write following code it works fine.

//   Microsoft.Office.Interop.Word.ApplicationClass wordApp = new

Microsoft.Office.Interop.Word.ApplicationClass();
string filePath1 = @"G:\ABOUT.docx";
object file = filePath1;
object nullobj = System.Reflection.Missing.Value;

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 nullobj, ref nullobj,
                                                                 ref nullobj);
Microsoft.Office.Interop.Word.Document doc1 = wordApp.ActiveDocument;
string m_Content = doc1.Content.Text;

txtbook.Text = m_Content;
doc.Close(ref nullobj, ref nullobj, ref nullobj);

but it is unable to read image files.

Please help I want to save whole content in database as html format and retrieve it in html format.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

2 Answers2

0

Note: This might not be the direct cause of your problem, but it needs to be mentioned and it's too long for a comment.

You are using Office automation to access Word documents from an ASP.NET application. This is not officially supported by Microsoft:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

So, apparently, the solution to your problem is to

Community
  • 1
  • 1
Heinzi
  • 167,459
  • 57
  • 363
  • 519
0

doc1.Content.Text

You can't use MS Word document content text, as it is not in the HTML format. (Which is require to display image and style on the ASP.NET web page)

Option 1

You can either convert document to HTML using Word Interop and get HTML markup in literal (Textbox won't work here)

Option 2

Use something like Google Doc viewer to view your Word document. There are paid viewers too, like Aspose, which you can use to view Word Document on ASP.NET site http://www.aspose.com/.net/word-component.aspx

In either case, you need to google and get more information on approaches, and implement for your ASP.NET website

Shabbir
  • 441
  • 2
  • 7
  • 17