Solved

How to read word document in ASP.net

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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