Solved

How to read word document in ASP.net

Posted on 2014-09-14
4
503 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 375 total points
ID: 40322485
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
ID: 40322493
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
ID: 40322507
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
ID: 40322617
Performance wise Aspose.Words is better...

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

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ado.net AddWithValue when using IN condition 7 42
e commerce steps shown instead of self testing 2 51
history of pages 7 47
Difference between Leaflet and MapBox? 5 42
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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