Reading a .doc file from ASP.Net

A

Abe

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?
 
G

Gaurav Khanna [C#/.NET MVP]

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/
 
Joined
Jul 23, 2006
Messages
1
Reaction score
0
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.
 
Joined
Aug 29, 2007
Messages
1
Reaction score
0
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???
 
Joined
Aug 27, 2008
Messages
1
Reaction score
0
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
 
Joined
Sep 28, 2012
Messages
2
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top