简体   繁体   中英

Convert from System.Byte[] to String fails

A product that we use is storing the Letter Express (Mail Merge) template as a BLOB (or CLOB...I cannot remember right now). We use the Product's API to call this letter express and send an email.

Now, we want the content of the email to be captured and stored in a separate field. The API provides us with a LetterExpress.WordDocument property which has the template. This is however a byte[] .

I am trying to get this into a string object so that I can populate the place holders and then store it in a different field.

This is the code that I was trying.

System.Text.Encoding.ASCII.GetString(LetterExpress.WordDocument)

However, I get an error as follows

The best overloaded method match for 'System.Text.Encoding.GetString(byte[])' has some invalid arguments

Why am I getting this error?

How can I ascertain what is the encoding that is being used for the LetterExpress.WordDocument? Or is there a generic method that can convert it into a string?

You're getting that error because the LetterExpress.WordDocument property you think is a byte[] really isn't one. Verify that the type of that property really is what you think it is.

It sounds like this is an actual .doc file, and a .doc file is much more complicated than just a string encoding. If you want to extract the text from a word document, you need something like the Aspose Tools . The ability to do this is not built into the framework. There is not System.Text.Encoding you can use, and no generic method including with .Net that can do this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM