Solved

How to read word document in ASP.net

Posted on 2014-09-14
4
484 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in page 3 46
Advice on Xojo as a development tool over VB. 4 39
Coding C# in Linux 8 31
Automated testing suggestions? 2 27
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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