简体   繁体   English

从System.Byte []转换为String失败

[英]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). 我们使用的产品将Letter Express(邮件合并)模板存储为BLOB(或CLOB ...我现在不记得了)。 We use the Product's API to call this letter express and send an email. 我们使用产品的API来调用此速递函并发送电子邮件。

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. 该API为我们提供了具有模板的LetterExpress.WordDocument属性。 This is however a byte[] . 但是,这是一个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 最佳重载方法匹配'System.Text.Encoding.GetString(byte [])'有一些无效的参数

Why am I getting this error? 为什么会出现此错误?

How can I ascertain what is the encoding that is being used for the LetterExpress.WordDocument? 如何确定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. 您会收到此错误,因为您认为是byte[]LetterExpress.WordDocument属性确实不是一个。 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. 听起来这是一个实际的.doc文件,并且.doc文件比仅仅是字符串编码要复杂得多。 If you want to extract the text from a word document, you need something like the Aspose Tools . 如果要从Word文档中提取文本,则需要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. 没有可以使用的System.Text.Encoding,也没有可以使用.Net的通用方法来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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