Free Support Forum -

Save to word doc on server


I’m sure this question gets asked alot but i couldn’t find anything.

I need to save the contents of an html text box to a word file on the server and I need to save it to a Database using a byte array.

I can create a file or a byte stream and save but I am able to get the resulting file to open in word, I get a pop up asking what program I want to open the file with. Do you have any code examples of how this can be done.


Please check out the example in this forum and let me know if that helps

I don’t think that thread really helps.

I take the contents of an html text box and create a word doc using aspose.

like this

Dim doc As Document

Dim fileName As String = keyDirectory & keyFileName

doc = word.Open(fileName)

Dim builder As New DocumentBuilder(doc)

With builder

.Font.Size = 11

.Font.Name = “Arial”


End With

’ then i take the word doc and save to a stream

‘’'Open the file stream for writing

’ myFilefs = New FileStream(“C:\Equicare\ClientLetter.doc”, FileMode.OpenOrCreate, FileAccess.ReadWrite)

doc.Save(myFilefs, SaveFormat.FormatText)

then I take the stream and read it to a byte array which I save to the DB using a stored proceedure

Dim MyData(myFilefs.Length) As Byte

myFilefs.Read(MyData, 0, myFilefs.Length)

This doesn’t work, I get the text to the DB but its not recognized as a word doc, any ideas???

After you saved to a stream, Stream.Position is at the end of the stream. If you read immediately from the stream, you can read only zero bytes. You need to seek to the stream beginning before you can read from it.

myFilefs.Seek(SeekOrigin.Begin, 0);