Gday All, I have a rich text box in a winforms app that I am attempting to copy the rich text (with formatting in tact) to an outlook message that I have created using Microsoft.Office.Interop.Outlook... However copying the rtf straight to the message does not work - the rtf code is displayed, rather than the formatted text. There does not appear to be an exposed rtf property to copy to (which would be ideal), unless you use something like Redemption by the looks of it which costs money and is not an option for me right now. So, then I tried to create a MSWord document, copy the rich text to this, save as html (in MSWord), then open up the saved html file and the generated html into the ..HTMLBody of the email message. I thought for sure this would work, but the MSWord generated HTML is not compatible with the Outlook HTML it would seem and as such some characers are not recognised and are displayed as '?' - not pretty. So I am wondering if anyone knows a way to copy rich text and have it display correctly in an Outlook message?? Thanks in advance,
Peter, Check MailItem 's BodyFormat property Note: I have just looked up msdn & didn't try writing any code to do it Does that work?
[quoted text, click to view] On Mon, 18 Feb 2008 23:54:07 -0800, mrstrong <p.strong@gmail.com> wrote: > [...] > So I am wondering if anyone knows a way to copy rich text and have it > display correctly in an Outlook message??
Not knowing the Outlook interop API, I can't tell you if there's a way to initialize an Outlook message with the actual RTF data directly. However, the RichTextBox control does have a Copy() method that will copy the current selection to the clipboard. I'm not a big fan of programmatically modifying the clipboard except when the user explicitly asks you to, but in this case it might be an acceptable compromise if you can't find a better way to do it directly. Of course, this would depend on the Outlook interop API including a method that allows you to paste into an Outlook message from the clipboard. Again, I don't know whether that exists. But it seems that might be more likely to exist than the other. :) By the way, if you find yourself looking again at your other workaround, the "HTML to Word to Outlook" technique, you might explore trying to fix the '?' characters with explicit setting of character encodings or fonts, either of which might lead to characters that are either unrecognized, incorrectly saved, or undisplayable in Outlook.
[quoted text, click to view] On Feb 19, 6:36 pm, Kalpesh <shahkalp...@gmail.com> wrote: > Peter, > > Check MailItem 's BodyFormat property > Note: I have just looked up msdn & didn't try writing any code to do > it > > Does that work? >
Unfortunately no - I was already doing that. Here is the code where I set the format for the message: msg.Message.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatHTML; Then I set the HTMLBody property of the message to be a string containing the HTML that I have pulled out of the html file that I have converted from MSWord.. Thanks,
On Feb 19, 6:38 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com> [quoted text, click to view] wrote: > On Mon, 18 Feb 2008 23:54:07 -0800, mrstrong <p.str...@gmail.com> wrote: > > [...] > > So I am wondering if anyone knows a way to copy rich text and have it > > display correctly in an Outlook message?? > > Not knowing the Outlook interop API, I can't tell you if there's a way to > initialize an Outlook message with the actual RTF data directly. > > However, the RichTextBox control does have a Copy() method that will copy > the current selection to the clipboard. I'm not a big fan of > programmatically modifying the clipboard except when the user explicitly > asks you to, but in this case it might be an acceptable compromise if you > can't find a better way to do it directly. > > Of course, this would depend on the Outlook interop API including a method > that allows you to paste into an Outlook message from the clipboard. > Again, I don't know whether that exists. But it seems that might be more > likely to exist than the other. :) > > By the way, if you find yourself looking again at your other workaround, > the "HTML to Word to Outlook" technique, you might explore trying to fix > the '?' characters with explicit setting of character encodings or fonts, > either of which might lead to characters that are either unrecognized, > incorrectly saved, or undisplayable in Outlook. >
Thanks Pete - I tried that too but the outlook message does not have a Paste() method unfortunately. Your other suggestion about character conversion is my last resort, but I wouldnt have thought it would be this hard to simply copy some rich text into an email!! Regards, Peter
[quoted text, click to view] On Tue, 19 Feb 2008 16:51:31 -0800, mrstrong <p.strong@gmail.com> wrote: > Thanks Pete - I tried that too but the outlook message does not have a > Paste() method unfortunately.
Really? That's surprising. I know that Excel and Word automation both support clipboard operations, via paste methods. I don't recall off the top of my head whether those methods are in the document classes (e.g. Worksheet) or part of the application API (e.g. Application). It's possible it's the latter, which would require activating the document of interest before executing the paste. Did you only look in the MailItem class for a paste operation? If so, you might also want to check to see if the Outlook application class has the method instead. Sorry I'm being so vague...I wish I had more experience with what you're doing and could offer better advice. But I'm hoping I can at least ensure that you haven't overlooked something useful. [quoted text, click to view] > Your other suggestion about character conversion is my last resort, > but I wouldnt have thought it would be this hard to simply copy some > rich text into an email!!
Well, I don't know that it is. I just don't know that it isn't, either. :) By the way, with respect to the suggestion from Kalpesh, I'm wondering if there's an RTF format you can use with the BodyFormat property instead of "olFormatHTML" (maybe it's called "olFormatRTF" :) ). Then you could set the Body property to the RTF you get directly from the RichTextBox rather than going through Word. Less conversion is always better and maybe that would address the issues you're running into, assuming such a format is supported. Who knows? It might even avoid the "missing character" problem as well. Anyway, good luck. For what it's worth, this C# newsgroup may not be the best place to look for help with this question. It's pretty remotely related to the main topic of the newsgroup. If you can find a forum that is more specific to automating Office applications, or even doing ..NET-to-Office interop specifically, you'd probably find people who have a lot more experience and can offer more specific advice.
On Feb 20, 11:06 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com> [quoted text, click to view] wrote: > On Tue, 19 Feb 2008 16:51:31 -0800, mrstrong <p.str...@gmail.com> wrote: > By the way, with respect to the suggestion from Kalpesh, I'm wondering if > there's an RTF format you can use with the BodyFormat property instead of > "olFormatHTML" (maybe it's called "olFormatRTF" :) ). Then you could set > the Body property to the RTF you get directly from the RichTextBox rather > than going through Word. Less conversion is always better and maybe that > would address the issues you're running into, assuming such a format is > supported. Who knows? It might even avoid the "missing character" > problem as well. >
Thanks that is what I tried initially but to no avail. The actual rtf code is displayed, rather than the actual formatted rtf. [quoted text, click to view] > Anyway, good luck. For what it's worth, this C# newsgroup may not be the > best place to look for help with this question. It's pretty remotely > related to the main topic of the newsgroup. If you can find a forum that > is more specific to automating Office applications, or even doing > .NET-to-Office interop specifically, you'd probably find people who have a > lot more experience and can offer more specific advice. >
Sure, I'll go looking. If I find a way forward I will let you know. Regards,
[quoted text, click to view] On Feb 20, 11:30 am, mrstrong <p.str...@gmail.com> wrote: > On Feb 20, 11:06 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com> > wrote: > > > On Tue, 19 Feb 2008 16:51:31 -0800, mrstrong <p.str...@gmail.com> wrote: > > By the way, with respect to the suggestion from Kalpesh, I'm wondering if > > there's an RTF format you can use with the BodyFormat property instead of > > "olFormatHTML" (maybe it's called "olFormatRTF" :) ). Then you could set > > the Body property to the RTF you get directly from the RichTextBox rather > > than going through Word. Less conversion is always better and maybe that > > would address the issues you're running into, assuming such a format is > > supported. Who knows? It might even avoid the "missing character" > > problem as well. > > Thanks that is what I tried initially but to no avail. The actual rtf > code is displayed, rather than the actual formatted rtf. > > > Anyway, good luck. For what it's worth, this C# newsgroup may not be the > > best place to look for help with this question. It's pretty remotely > > related to the main topic of the newsgroup. If you can find a forum that > > is more specific to automating Office applications, or even doing > > .NET-to-Office interop specifically, you'd probably find people who have a > > lot more experience and can offer more specific advice. > > Sure, I'll go looking. > > If I find a way forward I will let you know. >
OK - my extravagant solution is this: Clipboard.Clear(); richTxtBox.SelectAll(); richTxtBox.Copy(); // copy contents of the rich text box to clipboard... msg.Show(); // open the outlook message SendKeys.Send("^(v)"); // paste from the clipboard to the email message in Outlook. Good old sendkeys :) Hopefully this helps someone out there.
[quoted text, click to view] On Feb 20, 4:42 pm, mrstrong <p.str...@gmail.com> wrote: > On Feb 20, 11:30 am, mrstrong <p.str...@gmail.com> wrote: > > > > > On Feb 20, 11:06 am, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com> > > wrote: > > > > On Tue, 19 Feb 2008 16:51:31 -0800, mrstrong <p.str...@gmail.com> wrote: > > > By the way, with respect to the suggestion from Kalpesh, I'm wondering if > > > there's an RTF format you can use with the BodyFormat property instead of > > > "olFormatHTML" (maybe it's called "olFormatRTF" :) ). Then you could set > > > the Body property to the RTF you get directly from the RichTextBox rather > > > than going through Word. Less conversion is always better and maybe that > > > would address the issues you're running into, assuming such a format is > > > supported. Who knows? It might even avoid the "missing character" > > > problem as well. > > > Thanks that is what I tried initially but to no avail. The actual rtf > > code is displayed, rather than the actual formatted rtf. > > > > Anyway, good luck. For what it's worth, this C# newsgroup may not be the > > > best place to look for help with this question. It's pretty remotely > > > related to the main topic of the newsgroup. If you can find a forum that > > > is more specific to automating Office applications, or even doing > > > .NET-to-Office interop specifically, you'd probably find people who have a > > > lot more experience and can offer more specific advice. > > > Sure, I'll go looking. > > > If I find a way forward I will let you know. > > OK - my extravagant solution is this: > > Clipboard.Clear(); > richTxtBox.SelectAll(); > richTxtBox.Copy(); // copy contents of the > rich text box to clipboard... > msg.Show(); // open the outlook message > SendKeys.Send("^(v)"); // paste from the > clipboard to the email message in Outlook. >
After further testing, I added in a Sleep(50); just to give Outlook a bit of time to open up before the paste was done. Without this about 15% of the time it would not paste correctly, presumably because the Outlook message was not properly open yet before the paste was called. msg.Show(); System.Threading.Thread.Sleep(50); SendKeys.SendWait("^(v)"); Regards,
Don't see what you're looking for? Try a search.
|