473,320 Members | 2,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Saving a MS Word document in a string

Is it possible to save a MS Word document in a string? I suspect not because
Ive tried saving it in using various encoding formats and it always gets
corrupted.

Thanks
Andrew
Nov 16 '05 #1
4 3143
Andrew,

You could save it in a string, but it would require some translation.
Basically, you can read the byte stream, and then convert that to a unicode
string (might have to pad an extra empty byte in there). What is in the
string won't be pretty, and will look pretty much the same as if you opened
it up in notepad.

Now, if you need this string to be in something that can be embedded in
XML, or an email, or something of that nature, where the character set is
restrained, you are better off reading the byte stream and then converting
to base 64 (use the ToBase64String method on the Convert class).

Finally, if you are using the most recent version of office (2003), it
will save your documents in an XML format, if you wish, which is already a
string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew Inwards" <an****@nospam.com> wrote in message
news:uR**************@TK2MSFTNGP12.phx.gbl...
Is it possible to save a MS Word document in a string? I suspect not
because
Ive tried saving it in using various encoding formats and it always gets
corrupted.

Thanks
Andrew

Nov 16 '05 #2
Basically I need to be able to store binary files like word in a workflow
system which only supports basic types like string. I then need to be able
to put the file back into an application readable format for viewing.

Can you recommend an approach and do you have any sample code?

Thanks
Andrew

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eB****************@TK2MSFTNGP10.phx.gbl...
Andrew,

You could save it in a string, but it would require some translation.
Basically, you can read the byte stream, and then convert that to a unicode string (might have to pad an extra empty byte in there). What is in the
string won't be pretty, and will look pretty much the same as if you opened it up in notepad.

Now, if you need this string to be in something that can be embedded in XML, or an email, or something of that nature, where the character set is
restrained, you are better off reading the byte stream and then converting
to base 64 (use the ToBase64String method on the Convert class).

Finally, if you are using the most recent version of office (2003), it
will save your documents in an XML format, if you wish, which is already a
string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew Inwards" <an****@nospam.com> wrote in message
news:uR**************@TK2MSFTNGP12.phx.gbl...
Is it possible to save a MS Word document in a string? I suspect not
because
Ive tried saving it in using various encoding formats and it always gets
corrupted.

Thanks
Andrew


Nov 16 '05 #3
Andrew,

What is the encoding of the string? Basically, just open the file up
with the FileStream class, and then store the bytes in a byte array, and
pass them to the ToBase64String method on the Convert class.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew Inwards" <an****@nospam.com> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
Basically I need to be able to store binary files like word in a workflow
system which only supports basic types like string. I then need to be able
to put the file back into an application readable format for viewing.

Can you recommend an approach and do you have any sample code?

Thanks
Andrew

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:eB****************@TK2MSFTNGP10.phx.gbl...
Andrew,

You could save it in a string, but it would require some translation.
Basically, you can read the byte stream, and then convert that to a

unicode
string (might have to pad an extra empty byte in there). What is in the
string won't be pretty, and will look pretty much the same as if you

opened
it up in notepad.

Now, if you need this string to be in something that can be embedded

in
XML, or an email, or something of that nature, where the character set is
restrained, you are better off reading the byte stream and then
converting
to base 64 (use the ToBase64String method on the Convert class).

Finally, if you are using the most recent version of office (2003),
it
will save your documents in an XML format, if you wish, which is already
a
string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew Inwards" <an****@nospam.com> wrote in message
news:uR**************@TK2MSFTNGP12.phx.gbl...
> Is it possible to save a MS Word document in a string? I suspect not
> because
> Ive tried saving it in using various encoding formats and it always
> gets
> corrupted.
>
> Thanks
> Andrew
>
>



Nov 16 '05 #4
Thanks for your help- I've got it working with base 64. What are the
implications in terms of size. For example how much storage would be
required for a 50k word document.

Andrew
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eB****************@TK2MSFTNGP10.phx.gbl...
Andrew,

You could save it in a string, but it would require some translation.
Basically, you can read the byte stream, and then convert that to a unicode string (might have to pad an extra empty byte in there). What is in the
string won't be pretty, and will look pretty much the same as if you opened it up in notepad.

Now, if you need this string to be in something that can be embedded in XML, or an email, or something of that nature, where the character set is
restrained, you are better off reading the byte stream and then converting
to base 64 (use the ToBase64String method on the Convert class).

Finally, if you are using the most recent version of office (2003), it
will save your documents in an XML format, if you wish, which is already a
string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew Inwards" <an****@nospam.com> wrote in message
news:uR**************@TK2MSFTNGP12.phx.gbl...
Is it possible to save a MS Word document in a string? I suspect not
because
Ive tried saving it in using various encoding formats and it always gets
corrupted.

Thanks
Andrew


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Andy Davis | last post by:
How do i or can I open a word document directly from Access? I would like to be able for the user to click a button on my form to open a word document and then also run a macro in Word. Thanks...
1
by: Jose Egea | last post by:
Hello: I would like to make an application to manage word and pdf documents, opening and saving them in a sql database. Is there any way to open a document sending to the winword application a...
1
by: Adam Faulkner via DotNetMonster.com | last post by:
I had a problem before extracting pages from an existing word document and then inserting the content into a new word document. The following code below works with Microsoft Word 2000 Function...
1
by: rick m | last post by:
We have an access DB that 2 input people use to tracking incoming patients. There is a form for them to do this but they find it confusing to use (it's plainly laid out, no one else complains about...
0
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
0
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information...
2
by: Dean Richardson | last post by:
Hello, I am currently building a windows application in VB.NET. At the moment I have a word document saved locally which I open with the WebBrowser control. I cannot seem to save the changes...
0
by: Dean Richardson | last post by:
Hello, I am currently building a windows application in VB.NET. At the moment I have a word document saved locally which I open with the WebBrowser control. I cannot seem to save the...
2
by: ClearCut | last post by:
I have written a program in VB6 that opens an existing Word document and adds some text to the top of the document before printing it. Now I want to close the document without saving the changes. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.