0

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?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Kanini
  • 1,947
  • 6
  • 33
  • 58
  • Are you attempting to get a string that contains the _text_ in the template? – Mark Avenius Dec 13 '10 at 19:27
  • @Mark Avenius: Yes, that is exactly what we are attempting. – Kanini Dec 13 '10 at 19:28
  • I think you need to specify the encoding, but the error seems to be related to the data type of WordDocument itself. Maybe there's a LetterExpress.WordDocument.GetBytes? Disclaimer: never worked on LetterExpress – Tejaswi Yerukalapudi Dec 13 '10 at 19:31
  • 2
    What is the full signature of `LetterExpress.WordDocument`? – NOtherDev Dec 13 '10 at 19:31
  • @Kanini: there is more to a Word template than just the text, which explains why you are getting an error when converting the template's binary data to a string. – Mark Avenius Dec 13 '10 at 19:34
  • @Mark: So, how do I get the text which is inside the document? Any suggestions? – Kanini Dec 13 '10 at 19:37
  • @Kanini: I haven't worked much (read: at all) with Word Templates, so I am really not sure. Based on the title, I thought you were looking to string encode a `byte[]`, about which I do have experience. Per @Joel Coehoorn's suggestion, I would look at Aspose if I were you. – Mark Avenius Dec 13 '10 at 19:40

2 Answers2

3

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.

Adam Maras
  • 26,269
  • 6
  • 65
  • 91
  • I think it likely is a byte array, just with some parts in the array that are invalid ascii characters. – Joel Coehoorn Dec 13 '10 at 19:30
  • 1
    To me, it looks like LetterExpress is not a field or variable, but the name of a class. – jeroenh Dec 13 '10 at 19:32
  • @Joel if it was that, I wouldn't expect to get a signature match complaint. – Rex M Dec 13 '10 at 19:33
  • Duh! That was it. LetterExpress.WordDocument was not even a byte []. I had to convert it and then System.Text.Encoding..GetString() worked, but then it returned a string which did not make sense. I guess, we would have to go back to Aspose tools. – Kanini Dec 14 '10 at 07:38
1

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.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794