Saving a MS Word document in a string

  • Thread starter Thread starter Andrew Inwards
  • Start date Start date
A

Andrew Inwards

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
 
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.
 
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 said:
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]
- (e-mail address removed)

Andrew Inwards said:
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
 
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]
- (e-mail address removed)

Andrew Inwards said:
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

in
message news:eBTn3%[email protected]...
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]
- (e-mail address removed)

Andrew Inwards said:
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
 
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 said:
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]
- (e-mail address removed)

Andrew Inwards said:
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
 
Back
Top