HowTo: Set the icon of a folder item

Add-in Express™ Support Service
That's what is more important than anything else

HowTo: Set the icon of a folder item
Thanasis Boukouvalas

Posts: 40
Joined: 2006-06-17

I'd like to set the icon of a folder item (e.g. a mail), in order to show to the user that this item is registered to the CRM.
Is there any way to do this?
Posted 26 Sep, 2006 04:59:50 Top
Sergey Grischenko

Add-in Express team

Posts: 7235
Joined: 2004-07-05
Hi Thanasis.

To implement it you will need to customize the Outlook form.
I would advise you to add a new user property to the Outlook item (in the code of the add-in) that has been registered in the CRM. Then you need to customize the folder View to display this property.
Posted 26 Sep, 2006 08:50:09 Top
Thanasis Boukouvalas

Posts: 40
Joined: 2006-06-17
Hi Sergey

I've already use a user property (the CRM registration code) to indicate that item has been registered but I'd prefer to change the original item icon because I cannot find how I can change the folder View programmatically.

1. is there any way to change the "original" item icon or
2. if I use a second user property as "my" icon, is there a way to change the folder view programmatically (I suppose the second is more difficult)
Posted 26 Sep, 2006 13:27:55 Top
Sergey Grischenko

Add-in Express team

Posts: 7235
Joined: 2004-07-05
Hi Thanasis.

In this situation the first is more difficult. You will face difficulties with the add-in deployment since you will have to change the outlook form in the code of the add-in.
I would suggest you to create a new View for a folder using the Views collection of the Outlook folder (see the 'Views Collection' chapter in the Microsoft Visual Basic Help). You can create a new view based on the current view. In this case you will need to obtain the XML property of the folder and change the XML schema a little.
I have the example code. I used to implement this algorithm for incoming emails. This is the Delphi code. I hopy you will manage to understand it.

procedure TDWMWMainForm.NewMessage(var Message: TMessage);
olTableView = $00000000;
olCardView = $00000001;
olCalendarView = $00000002;
olIconView = $00000003;
olTimelineView = $00000004;

olViewSaveOptionThisFolderEveryone = $00000000;
olViewSaveOptionThisFolderOnlyMe = $00000001;
olViewSaveOptionAllFoldersOfType = $00000002;

NamedPropertyRec: NamedPropertyRecord;
Msg: TRwMapiMessage;
MsgId : TRwEntryId;
FolderId : TRwEntryId;
StrMsgId: PChar;
PropertyTag: Cardinal;
TaskID, SAPFolderName: string;
DWMailID: string;
Inbox: TRwMapiFolder;
TaskFolder: TRwMapiFolder;
OlRootFolder: OleVariant;
OlTaskFolder: OleVariant;
ViewExists: Boolean;
OlViews: OleVariant;
OlView: OleVariant;
OlMailItem: OleVariant;
XmlString, DWColumns: string;
i, p, n: Integer;
Headers: TStringList;
//Text: TStringList;
ExprLabel, s: String;
NewMsgID: String;
OlExplorer: OleVariant;
PropItem: TRwMapiPropItem;
Number: Integer;
n := 0; Number := -1;

WriteToLog('Inside of NewMessage procedure.');

StrMsgId := PChar(Message.WParam);
MsgId := StringToRwEntryID(string(StrMsgId));

WriteToLog('The message ID is ' + StrMsgId);

Msg := MsgStore.OpenMessage(MsgId, alBestAccess);

WriteToLog('Getting the WorkItemID property...');

PropItem := Msg.NamedPropByID(gc_DWTaskID, DWMailID_GUIID, False, PT_STRING8);
if (PropItem <> nil) then begin

WriteToLog('Getting the TaskID property...');

TaskID := Trim(PropItem.AsString); //.NamedPropByID(gc_DWTaskID, DWMailID_GUIID, False, PT_STRING8).AsString;
if TaskID <> '' then begin

WriteToLog('Processing the ' + TaskID + ' property (TaskID).');

DWMailID := Msg.NamedPropByID(gc_DWMailID, DWMailID_GUIID, False, PT_STRING8).AsString;

Inbox := MsgStore.OpenFolder(Msg.FolderID, alBestAccess);

WriteToLog('Creating the ' + TaskID + ' folder.');

SAPFolderName := Msg.NamedPropByID(gc_DWTaskTextID, DWMailID_GUIID, False, PT_STRING8).AsString;
if SAPFolderName = '' then
SAPFolderName := TaskID;

TaskFolder := FindFolder(Inbox, SAPFolderName, TaskID, Number);
if TaskFolder = nil then begin
if Number >= 0 then
SAPFolderName := SAPFolderName + ' ' + IntToStr(Number + 1);
TaskFolder := Inbox.CreateFolder(SAPFolderName, 'Desktop Workplace work items (Task ID = ' + TaskID + ').', True);

WriteToLog('Moving the ' + TaskID + ' folder.');

Inbox.MoveMessage(MsgId, TaskFolder);

NamedPropertyRec.PropertyID := gc_DWMailID;
NamedPropertyRec.GUIID := DWMailID_GUIID;
NamedPropertyRec.Value := DWMailID;

WriteToLog('Finding a new email in the ' + TaskID + ' folder.');

NewMsgID := FindMail(NamedPropertyRec, TaskFolder.FolderId);
OlMailItem := Namespace.GetItemFromID(NewMsgID, RwEntryIDToOutlookID(Msg.MessageStoreID));

WriteToLog('The email has been found. Adding user properties...');

for i:=1 to 6 do begin
PropertyTag := Msg.CreateNamedProperty(gc_DWCustomID + IntToStr(i), DWMailID_GUIID, PT_STRING8);
if (Msg.HasProp(PropertyTag)) then begin
ExprLabel := Msg.NamedPropByID(gc_DWCustomID + IntToStr(i), DWMailID_GUIID, False, PT_STRING8).AsString;
OlMailItem.UserProperties.Add('EXPRLABEL' + IntToStr(i), 1, True);
OlMailItem.UserProperties.Item('EXPRLABEL' + IntToStr(i)) := ExprLabel;
WriteToLog('The EXPRLABEL' + IntToStr(i) + ' property has just been added.');

WriteToLog('Finding the ' + TaskID + ' folder.');

OlTaskFolder := Namespace.GetFolderFromID(RwEntryIDToOutlookID(TaskFolder.FolderId), RwEntryIDToOutlookID(Msg.MessageStoreID));
OlViews := OlTaskFolder.Views;

WriteToLog('The folder has been found. Finding the DWView...');

ViewExists := False;
for i := 1 to OlViews.Count do
if OlViews.Item(i).Name = 'DWView' then begin
ViewExists := True;
OlView := OlViews.Item(i);
{Text := TStringList.Create;
Text.Text := OlView.XML;

WriteToLog('The DWView view has been found.');


if not ViewExists then begin

WriteToLog('The DWView view hasn''t been found. Adding a new view...');

OlView := OlViews.Add('DWView', olTableView, olViewSaveOptionThisFolderEveryone);
XmlString := OlView.XML;

WriteToLog('The original view is ' + XmlString);

WriteToLog('Getting the <orderby> tag position...');

p := Pos('<orderby>', XmlString);
if p > 0 then begin
DWColumns := '';

WriteToLog('The position is ' + IntToStr(p));

WriteToLog('Getting headers from SAP...');
Headers := GetHeaders(DWMailID, TaskID);

if Headers.Count > 0 then begin

for i:= 0 to Headers.Count - 1 do begin

DWColumns := DWColumns + #$D#$A#9 + '<column>';

WriteToLog('Processing the ''' + Headers[i] + ''' header.');

DWColumns := DWColumns + #$D#$A#9#9 + '<heading>' + Headers[i] + '</heading>';
DWColumns := DWColumns + #$D#$A#9#9 + '<prop>{00020329-0000-0000-C000-000000000046}/EXPRLABEL' + IntToStr(i+1) + '</prop>';
DWColumns := DWColumns + #$D#$A#9#9 + '<type>string</type>';
DWColumns := DWColumns + #$D#$A#9#9 + '<width>22</width>';
DWColumns := DWColumns + #$D#$A#9#9 + '<style>padding-left:3px;;text-align:left</style>';
DWColumns := DWColumns + #$D#$A#9#9 + '<userheading>' + Headers[i] + '</userheading>';
DWColumns := DWColumns + #$D#$A#9 + '</column>';
if DWColumns <> '' then begin
DWColumns := DWColumns + #$D#$A#9;
Insert(DWColumns, XmlString, p);

WriteToLog('The new view is ' + XmlString);

OlView.XML := XmlString;

WriteToLog('The new is saved.');

// For some reason Outlook raises an exeception when it is run in the background,
// but the DW view is applied successfully.

WriteToLog('The new is applied.');



OlExplorer := Unassigned;
OlView := Unassigned;
OlViews := Unassigned;
OlMailItem := Unassigned;
OlTaskFolder := Unassigned;
OlRootFolder := Unassigned;
//if PropItem <> nil then
// PropItem.Free;
if TaskFolder <> nil then
if Inbox <> nil then
if Msg <> nil then

on e: SysUtils.Exception do begin
//ShowDWMsg('Desktop Workplace Mail Watcher error', e.Message, mtError, False);
WriteToLog('Error: ' + e.Message);

Posted 27 Sep, 2006 11:38:35 Top
Thanasis Boukouvalas

Posts: 40
Joined: 2006-06-17
Hi Sergey and thank you very very very much.

I didnt known that I could create programmatically a folder view with XML.
Now I can have a view based on the current view with one more column.

Do you known if I can show an icon (rather that text) like attachment column does?

I cannot find any documentation about how a boolicon column can set the icon

<heading>Registered at Entersoft CRM</heading>

Attachment column:
Posted 29 Sep, 2006 09:22:52 Top
Sergey Grischenko

Add-in Express team

Posts: 7235
Joined: 2004-07-05
Hi Thanasis.

The fact is that the Outlook.OlUserPropertyType enumeration doesn't contain the Icon property type. But you can use the Yes/No type instead.
You can read more about the Add method of the UserProperties interface in the Microsoft Visual Basic Help in Outlook.
Posted 29 Sep, 2006 16:38:06 Top