Solved

How to read word document in ASP.net

Posted on 2014-09-14
4
463 Views
Last Modified: 2014-09-16
Hi,

I am trying to read content from word document using asp.net.can u plz give me example how to read word document.

Any software or dll's are required for this?
if there can you please give those details also
0
Comment
Question by:mannevenu26
  • 2
4 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 375 total points
Comment Utility
It does depend exactly what you are trying to do, and what version of Word you need to support. In most cases it will be easier to use a 3rd party component. One I have used is http://www.aspose.com/.net/word-component.aspx

If you only need to handle docx files then OpenXML (which is free) may do the job, but its more complex (in my experience) http://msdn.microsoft.com/en-us/library/office/bb448854(v=office.15).aspx

HTH
0
 

Author Comment

by:mannevenu26
Comment Utility
we need both doc and docx.
Performance wise which one is better?OpenXML or Officeinteropt?

can u plz give sample code for both
0
 
LVL 12

Assisted Solution

by:Ramkisan Jagtap
Ramkisan Jagtap earned 125 total points
Comment Utility
Sample code to open document with Microsoft.Office.Interop

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="TextBox1" runat="server" Height="722px" Width="100%"
            TextMode="MultiLine"></asp:TextBox>
   
    </div>
    <div>
   
        <asp:FileUpload ID="FileUpload1" runat="server" BorderStyle="Double"
            Width="549px" /> <asp:Button ID="Button1" runat="server" Text="Button"
            onclick="Button1_Click" />
   
    </div>
    </form>
</body>
</html>

Open in new window


protected void Button1_Click(object sender, EventArgs e)
      {
      
       
        Microsoft.Office.Interop.Word.ApplicationClass AC = new Microsoft.Office.Interop.Word.ApplicationClass();
        Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
          object readOnly = false;
          object isVisible = true;
          object missing = System.Reflection.Missing.Value;
          try
          {
              doc = AC.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
              TextBox1.Text = doc.Content.Text;
          }
          catch (Exception ex)
          {
              MessageBox.Show("ERROR: " + ex.Message);
          }
          finally
          {
              doc.Close(ref missing, ref missing, ref missing);
          }
    }

Open in new window

0
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 375 total points
Comment Utility
Performance wise Aspose.Words is better...

MS themselves recommend not to use http://support.microsoft.com/kb/257757
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now