Vineed


I have a VB.Net application wherein I process a word document. The problem I am facing is as follows

I have a word document, I need to read the content of the word document and do some processing with the document. Then I need to create a new document and write the contents.

I tried using a Stream objects found System.IO namespace but the format of the file i.e the characters in bold, the bullets, etc were not written to the new file.

Is there something wrong in the way I am using the Stream object or should I use some other classes from System.IO

The code that I have written in VB.Net is as follows:

dim strText as String

strText = File.ReadAllText("Document.doc")

' Here I do the processing with the string

File.CreateText("Document1.doc")

File.WriteAllText("Document1.doc", strText)

Please Help

Vineed



Re: Reading from Doc file onto a Reader

Feng Chen - MSFT


Hi Vineed,

The word document which extension is .doc has very complex format and cannot be handled simply using TextStream(File.ReadAllText of StreamWriter...). And the this complex format is Microsoft Confidental.

But you can try the Microsoft Word Object Library in your .net applications.

There are several references on this issue:

Understanding the Word Object Model from a .NET Developer's Perspective

Easily utilise Microsoft Word functionality in your .NET application

Hope this can help you!

Thanks!






Re: Reading from Doc file onto a Reader

Vineed

Feng Chen,

Thanks for your time, the link you provided me was helpful. But I need some more help. I was not able to figure out exactly how I would be able to retrieve data from the word document and even for that matter keep it on a clipboard.

Can you or anyone please help me out in this

Once again.........

Thanks Feng Chen

Vineed






Re: Reading from Doc file onto a Reader

Feng Chen - MSFT

Hi Vineed,

I think the code example in Understanding the Word Object Model from a .NET Developer's Perspective has showed how you can do that, though a little complex.

There's an article which shows how you can open a word file and grabs its contents in VB.net.

Hope this can help you.

Thanks!






Re: Reading from Doc file onto a Reader

Vineed

Hi Feng Chen

Thanks again for your time and effort.

The article you provided me has simplified certain issues. But still when I create a new document after processing the existing document I am not able to maintain its formatting.

Also can you please let me now if there are any good third party Asp.net controls that display a Word document within the browser. Something similar to a richtextbox. I went to Google and found some controls which work or rather look similar to a Word document, but they do not provide functionality to open an existing document. There also I have tried the method that you have shown me, but the formatting goes for a toss.

Please help me........

Thanks & regards

Vineed





Re: Reading from Doc file onto a Reader

Feng Chen - MSFT

Hi Vineed,

You can use WebBrowser Control to Open an office document in your Visual Basic.net application.

For more details, visit: How To Use the WebBrowser Control to Open an Office Document in Visual Basic .NET

This should fulfill your demand.

Thanks!






Re: Reading from Doc file onto a Reader

Vineed

Hi Feng Chen

Thanks for your time.

The solution you have given me is good and will work for the time being; but I was actually looking for something Web based to be based on the Internet. But this thing will work fine.

Once again Thanks for your time

Regards

Vineed





Re: Reading from Doc file onto a Reader

kwek

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 in web based application. I have to read the whole content of the doc file.And will start to find the content from the references below.

Example:

********

other content

********
REFERENCE

[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 example code to read and search all the "title" from doc.

I am trying Interop.Word. There are some problem i cant solve. The code can compile without an error .Bt no result come out.

Example Of Code (Just want to get the doc content)

Dim myWordDoc As Word.Document

Dim myWord As Word.Range

myWordDoc = myWordApp.Documents.Open(Server.MapPath("Doc\test.doc"))

For Each myWord In myWordDoc.Sentences

If InStr(myWord.Text, "REFERENCES", CompareMethod.Text) <> 0 Then

myWordDoc.Range(ThisDocument.Sentences(myWordDoc.Sentences.Count).Start, ThisDocument.Sentences(myWordDoc.Sentences.Count).End)

Me.txtContent.Text = String.Format(Format, myWordDoc.Sentences.First)

bolFound = True

Exit For

End If

Next

myWordDoc = myWordApp.ActiveDocument

myWord = myWordDoc.Range(0, 5)

myWord.Select()

Me.txtContent.Text = myWord.Text

myWordDoc.Close() 'close the word doc

myWordApp.Quit() 'Quit the word app

myWord = Nothing

myWordDoc = Nothing

Please help me.

Is there any note or tutorial that i can refer to.

Thanks.





Re: Reading from Doc file onto a Reader

kwek

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 in web based application. I have to read the whole content of the doc file.And will start to find the content from the references below.

Example:

********

other content

********
REFERENCE

[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 example code to read and search all the "title" from doc.

I am trying Interop.Word where you suggested url Understanding the Word Object Model from a .NET Developer's Perspective. There are some problem i cant solve. The code can compile without an error .Bt no result come out.

Example Of Code (Just want to get the doc content)

Dim myWordDoc As Word.Document

Dim myWord As Word.Range

myWordDoc = myWordApp.Documents.Open(Server.MapPath("Doc\test.doc"))

For Each myWord In myWordDoc.Sentences

If InStr(myWord.Text, "REFERENCES", CompareMethod.Text) <> 0 Then

myWordDoc.Range(ThisDocument.Sentences(myWordDoc.Sentences.Count).Start, ThisDocument.Sentences(myWordDoc.Sentences.Count).End)

Me.txtContent.Text = String.Format(Format, myWordDoc.Sentences.First)

bolFound = True

Exit For

End If

Next

myWordDoc = myWordApp.ActiveDocument

myWord = myWordDoc.Range(0, 5)

myWord.Select()

Me.txtContent.Text = myWord.Text

myWordDoc.Close() 'close the word doc

myWordApp.Quit() 'Quit the word app

myWord = Nothing

myWordDoc = Nothing

Please help me.

Is there any note or tutorial that i can refer to.

Thanks