TaskItem and AppointmentItem formated body

G

Guest

Is there any way to insert a HTML or RTF text in the body of a TaskItem and
AppointmentItem?
 
K

Ken Slovak - [MVP - Outlook]

Task and Appointment items always have RTF bodies. You can add RTF to the
body but it must be properly formatted of course and you'd have to set it
using a lower level API than the Outlook object model. If you add formatted
RTF to Body you'd see all the RTF tags and no formatting.

The property you'd need to use is PR_RTF_COMPRESSED (0x10090102), a
PT_BINARY property that would be written as a byte array. The byte array
would be the formatted RTF text.

You would need to use CDO 1.21 or Extended MAPI (C++ or Delphi only) or a
MAPI wrapper such as Redemption (www.dimastr.com/redemption) to be able to
do what you want.
 
G

Guest

thx for the respone.

any chance of an example in .NET for saving in RTF format?

i'm using the MAPI library in .net but i can't seem to figure out how to use
PR_RTF_COMPRESSED
 
K

Ken Slovak - [MVP - Outlook]

What MAPI library? If you're using CDO 1.21 that's not supported at all for
use in .NET code. I have no CDO code that is for .NET.

Also, .NET doesn't mean very much, are you using VB or C#?
 
D

Dan Mitchell

=?Utf-8?B?cmF6dmFudGlt?= said:
i'm using the MAPI library in .net but i can't seem to figure out how
to use PR_RTF_COMPRESSED

If you were using ExMAPI normally, you'd do:

OpenProperty(PR_RTF_COMPRESSED) to get the compressed stream
WrapCompressedRTFStream() to get an uncompressed stream out

then use standard IStream operations on that stream, and call RTFSync
when you're done. See the documentation for PR_RTF_COMPRESSED,
basically.

I don't know what's in the "MAPI library" you're using, but you should
look for functions that are similar to those ones. I don't know which
bit of the CLR is for IStream once you're out of the ExMAPI code, but
there must be something in there somewhere.

Oh, and as Ken mentions, .Net + CDO1.21 (or ExMAPI) aren't supported.
They may work, but if mysterious things go wrong, the answer is "don't
mix those things".

http://support.microsoft.com/kb/813349
http://support.microsoft.com/kb/872895

-- dan
 
G

Guest

i have developed an application in VS2005 C# that manipulates outlook unsing
VSTO. but now i'm verry frustrated i can't add RTF content or any formated
content in body of an appoinmnent or task. I woud really apreciate an example
in C# how to open a mail based by its ID or any other cryteria and simply
change its body content to a RTF one.
 
K

Ken Slovak - [MVP - Outlook]

As mentioned before you need to use a lower level API than the Outlook
object model to do what you want. You should not be using CDO 1.21 or
Extended MAPI from .NET code. It might work but when you run into problems
there are no fixes or support, since it's not supported. CDO is also subject
to the Outlook security and is not installed by default when Office is
installed, although it's an optional installation on the Office CD's.

You can use Redemption for what you want but it's a 3rd party library and
must be purchased if you intend to distribute your code.

What I would recommend would be to create a COM wrapper around the CDO code
calls if you want to use CDO and calling your COM wrapper DLL from your .NET
code. That would avoid the problems of directly calling CDO code from .NET
code.

Here is how the code would look (using VB 6) from the COM side, to call CDO,
which requires a reference to be set to CDO 1.21 (CDO.DLL) not one of the
many other CDO's.

' code would get EntryID of the task or appointment passed in to it
Dim oSession As MAPI.Session
Dim oMessage As MAPI.Message
Dim oField As MAPI.Field

Const PR_RTF_COMPRESSED = &H100901102

Set oSession = CreateObject("MAPI.Session")

'only works if Outlook is already running
oSession.Logon "", "", False, False

Set oMessage = oSession.GetItem(strEntryID)
Set oField = oMessage.Fields(PR_RTF_COMPRESSED)
'that field will be Empty if no body text exists for the task or appt.
' check for IsEmpty() before trying to use and handle access errors.

You would add your RTF formatted data to that field as follows:

oField.Value = strRTFtext
oMessage.Update

then set everything to Nothing after using oSession.Logoff to release the
session.
 
K

Ken Slovak - [MVP - Outlook]

Ooops. I forgot when I wrote that quickie code snippet that
PR_RTF_COMPRESSED is a PT_BINARY and not a PT_STRING8 property. That means
you will need to convert the string containing the RTF from string into a
byte array before you set the field to the value.
 
D

Dan Mitchell

Ken Slovak - said:
Ooops. I forgot when I wrote that quickie code snippet that
PR_RTF_COMPRESSED is a PT_BINARY and not a PT_STRING8 property. That
means you will need to convert the string containing the RTF from
string into a byte array before you set the field to the value.

And it has to be a _compressed_ byte array, thus the call to
WrapCompressedRTFStream. I don't think you can do this at all with just
plain CDO1.21 -- see

http://support.microsoft.com/kb/q172038/

for a helper DLL, though.

-- dan
 
G

Guest

i've managed with CDO 1.2 to access CdoPR_RTF_COMPRESSED.

here is the C# code i've used

MAPI.Session session = new MAPI.Session();
session.Logon(Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value);
MAPI.Message msg =
(MAPI.Message)session.GetMessage("000000008412BE0A84F77C48BB16457F22A3A74124702500", Missing.Value);

MAPI.Fields flds = (MAPI.Fields)msg.Fields;
MAPI.Field fls =
(MAPI.Field)flds.get_Item(MAPI.CdoPropTags.CdoPR_RTF_COMPRESSED,
Missing.Value);

how can i convert a string so the fls.value will accept it?

dan, the dll you poninted me (mapirtf.dll) to convert string to rtf
compressed binary is not working when i try to register or use it.
 
D

Dan Mitchell

=?Utf-8?B?cmF6dmFudGlt?= said:
i've managed with CDO 1.2 to access CdoPR_RTF_COMPRESSED.

Yes, but that won't be any use to you, because as has been said a number
of times, that's the _compressed_ version.
how can i convert a string so the fls.value will accept it?

That's binary -- you need to use whatever C# has for binary types in
variants.
dan, the dll you poninted me (mapirtf.dll) to convert string to rtf
compressed binary is not working when i try to register or use it.

That's almost certainly because you're using .Net. Again, as has been
said, this is not supported, and some things just plain can't be done.
This may well be one of them. I'd suggest asking in one of the .Net groups
for more on how to get the interop aspect of things working, though.

-- dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top