By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

Saving a MS Word document in a string

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.