Reading a .doc file from ASP.Net

Discussion in 'ASP .Net' started by Abe, Jan 22, 2004.

  1. Abe

    Abe Guest

    HI,

    using VB.net I need to access .doc file. Parse it's contents and then
    output the contents in an email.

    The question is how do I open a .doc (word) file in VB.net. Also, when
    I display the contents in the email I want to maintain the layout but
    I'm concern about the .doc control char in the document.

    any ideas?
    Abe, Jan 22, 2004
    #1
    1. Advertising

  2. Hi!

    You can consider using the Office PIA (Primary Interop Assemblies), automate
    Word and open the document in it, and extract the relevant portions from the
    same, preserving the formatting.

    --
    Regards,
    Kumar Gaurav Khanna
    -----------------------------------------------------------------
    Microsoft MVP - C#/.NET, MCSE Windows 2000/NT4, MCP+I
    WinToolZone - Spelunking Microsoft Technologies
    http://www.wintoolzone.com/
    OpSupport - Spelunking Rotor
    http://opsupport.sscli.net/
    Bangalore .NET Users' Group
    http://groups.msn.com/bdotnet/
    "Abe" <> wrote in message
    news:...
    > HI,
    >
    > using VB.net I need to access .doc file. Parse it's contents and then
    > output the contents in an email.
    >
    > The question is how do I open a .doc (word) file in VB.net. Also, when
    > I display the contents in the email I want to maintain the layout but
    > I'm concern about the .doc control char in the document.
    >
    > any ideas?
    Gaurav Khanna [C#/.NET MVP], Jan 23, 2004
    #2
    1. Advertising

  3. Abe

    nlaginha

    Joined:
    Jul 23, 2006
    Messages:
    1
    Hi friends, I saw this post, and I need to get an answer for my problem. Do you know how can I read the number of pages of a word document?using asp.NET or PHP or VB.NET anything....I really need to do this, and I´ve been searching for months.
    nlaginha, Jul 23, 2006
    #3
  4. Abe

    sjkwek

    Joined:
    Aug 29, 2007
    Messages:
    1
    Reading doc file with some criteria

    Hi...

    I am new to VB.net. Curretly i working with my final year project. Nw i need to read and find the content from the doc file. I have to read the whole content of the doc file.And will start to find the content from the references below.

    Example:

    References:

    [1] L. Bernstein, “Get The Design Right”. IEEE Software, Vol. 10 No. 5, September 1993, pp. 61-63.

    [2] Z. Razak, “The Internet Global Villages”, in Using IT to Build a Better Future Conference, Kuala Lumpur, 3 October 1995.


    i need to get content within quotes “ ” from the references which is the title. Is there any solution to read and search all the "title" from doc???
    sjkwek, Aug 29, 2007
    #4
  5. Abe

    ganesh1975

    Joined:
    Aug 27, 2008
    Messages:
    1
    Code for read DOC file and save as HTML, text , Word XML File


    Here is the code that helps to read any document (like .doc document file ) from specified location. This is a web based application and this code is written in VB.NET class as code behind in ASP.Net 2.0, where the word document is hard to upload from client side. Here is the code that uploads the document file and stores as HTML, text , Word XML File


    --------------------------------------------------------------------------

    Imports System
    Imports System.ComponentModel
    Imports Microsoft.Office.Interop
    Public Class WordAppl

    Private oWordAppl As Word.ApplicationClass

    Private oDoc As Word.Document

    Public Sub New()

    oWordAppl = New Word.ApplicationClass

    End Sub

    ' Open a file (the file must exists) and activate it

    Public Sub Open(ByVal strFileName As String)

    Dim fileName As Object = strFileName

    Dim readOnly1 As Object = False

    Dim isVisible As Object = True

    Dim missing As Object = System.Reflection.Missing.Value

    oDoc = oWordAppl.Documents.Open(fileName, missing, readOnly1, missing, missing, missing, missing, missing, missing, missing, missing, isVisible)

    oDoc.Activate()

    End Sub

    Public Sub Open()

    Dim missing As Object = System.Reflection.Missing.Value

    oDoc = oWordAppl.Documents.Add(missing, missing, missing, missing)

    oDoc.Activate()

    End Sub

    Public Sub Quit()

    Dim missing As Object = System.Reflection.Missing.Value

    oWordAppl.Application.Quit(missing, missing, missing)

    End Sub

    Public Sub Save()

    oDoc.Save()

    End Sub

    Public Sub SaveAs(ByVal strFileName As String)

    Dim missing As Object = System.Reflection.Missing.Value

    Dim fileName As Object = strFileName

    Dim docType As Integer
    docType = 2 ' Read doc file as Txt file
    ' docType = 10 ' Read doc file as HTML file
    ' docType = 11 ' Read doc file as XML file

    oDoc.SaveAs(fileName, 2) ', missing, missing, missing, missing, missing, missing, missing, missing, missing)

    End Sub

    Public Sub FindAndReplacement(ByVal strFind As String, ByVal strReplace As String)

    Try

    oWordAppl.Selection.HomeKey(Word.WdUnits.wdStory, Word.WdMovementType.wdExtend)

    With oWordAppl.Selection.Find

    .Text = strFind

    With .Replacement

    .Text = strReplace

    End With

    .Execute(Replace:=Word.WdReplace.wdReplaceAll)

    End With

    Catch ex As Exception

    'ClientUtilities.ShowErrorMessage(ex)

    End Try

    End Sub

    End Class

    ----------------------------------------------------------------------
    use in your code behind page.

    'for Open a word document.

    WordAppl.Open('Word File name')

    'for save file as text
    WordAppl.save(server.mappath("/") & "/" & "filename")



    see other information related to aspnet35 blogspot site
    ganesh1975, Nov 23, 2008
    #5
  6. Abe

    Larry Neblett

    Joined:
    Sep 28, 2012
    Messages:
    2
    You may look at the solution from devtriogroup.com (Word Reader .NET) that we have used in our project. Below is the snippet of vb.net code:

    ' Creates a new instance of Document class and reads a .doc file into this structure
    Dim Doc As New Document()
    Doc.ReadDoc("..\..\Data\WordTextFormatting.doc")

    ' Gets two first text runs, in this example - two sentences
    For i As Integer = 0 To 1
    ' Gets text run
    Dim tTextRun As TextRun = DirectCast(Doc.Sections(0).Nodes(0), Paragraph).TextRuns(i)

    ' Writes its properties
    textBox1.Text += "=== Text run " & (i + 1).ToString & " ===" & vbCr & vbLf
    textBox1.Text += "Text" & vbTab & vbTab & vbTab & ": " + tTextRun.Text & vbCr & vbLf
    textBox1.Text += "Font name" & vbTab & vbTab & ": " + tTextRun.Style.FontName & vbCr & vbLf
    textBox1.Text += "Font size" & vbTab & "(in half-point)" & vbTab & ": " + tTextRun.Style.FontSize.ToString & vbCr & vbLf
    textBox1.Text += "Text color" & vbTab & vbTab & vbTab & ": " + tTextRun.Style.TextColor.ToString & vbCr & vbLf
    textBox1.Text += "Bold" & vbTab & vbTab & vbTab & ": " + tTextRun.Style.FontStyle.Bold.ToString & vbCr & vbLf
    textBox1.Text += "Italic" & vbTab & vbTab & vbTab & ": " + tTextRun.Style.FontStyle.Italic.ToString & vbCr & vbLf
    textBox1.Text += "Underlined" & vbTab & vbTab & ": " + tTextRun.Style.FontStyle.Underlined.ToString & vbCr & vbLf
    textBox1.Text += "Strike-out" & vbTab & vbTab & vbTab & ": " + tTextRun.Style.FontStyle.StrikeOut.ToString & vbCr & vbLf & vbCr & vbLf
    Next
    Larry Neblett, Sep 28, 2012
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Wallace
    Replies:
    0
    Views:
    457
    John Wallace
    Jul 22, 2003
  2. Thomas Scheiderich

    Reading a Doc file from .net

    Thomas Scheiderich, Jun 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    386
    Ken Cox [Microsoft MVP]
    Jun 14, 2004
  3. Replies:
    0
    Views:
    451
  4. Matt
    Replies:
    3
    Views:
    484
    Tor Iver Wilhelmsen
    Sep 17, 2004
  5. Replies:
    0
    Views:
    127
Loading...

Share This Page