|
Mykhaylo Boreyko
Guest
|
Hello.
I'm developing Outlook 2007/2010 add-in.
And I need to create custom folders when add-in is initializing and add them to favorites group.
I've created custom folders, but I dont know how to add them to favorites.
I use AddToPFFavorites method on added folder, but it throws exception "The operation failed. An object could not be found".
Is there another method to add folder to favorites? |
|
Posted 16 Oct, 2012 09:04:13
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Hello Mykhaylo,
Can you please post some code or send it to the support email address (see readme.txt)? In the latter case, please make sure that your email contains a link to this topic.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 16 Oct, 2012 10:59:32
|
|
Top
|
|
Mykhaylo Boreyko
Guest
|
Here is code for adding folder
function CreateFolder(): MAPIFolder;
var
sentFolder: MAPIFolder;
begin
sentFolder := OutlookApp.GetNamespace('MAPI').GetDefaultFolder(olFolderSentMail);
result := sentFolder.Folders.Add('Custom', EmptyParam);
if Assigned(result) then
result.AddToPFFavorites(); // <<--- exception throws here.
end;
|
|
Posted 16 Oct, 2012 12:25:26
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Hi Mykhaylo,
I'd suggest checking if AddToPFFavorites() works for an existing folder. If it works, try to use a timer to call AddToPFFavorites after a small delay. Also check if navigating to the newly creating folder (set Explorer.CurrentFolder) before calling AddToPFFavorites() helps.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 17 Oct, 2012 06:36:43
|
|
Top
|
|
Mykhaylo Boreyko
Guest
|
I have already tried calling this function on existing folder. Without luck. Same exception is thrown.
Maybe this function is not for this purpose?
From MDSN about AddToPFFavorites method:
"Adds a Microsoft Exchange public folder to the public folder's Favorites folder."
But my custom folder is not Microsoft Exchange public folder, maybe this is the reason of error. |
|
Posted 17 Oct, 2012 06:56:46
|
|
Top
|
|
Mykhaylo Boreyko
Guest
|
Outlook 2010 has button "Show in Favorites" in "Folder" ribbon group for this purpose.
Is there some way or extension to outlook to see what this button does? |
|
Posted 17 Oct, 2012 07:18:30
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
|
Posted 17 Oct, 2012 11:16:44
|
|
Top
|
|
Mykhaylo Boreyko
Guest
|
Thank you for link. It was helpful.
As result, my final method to add folder to favorites is
procedure TProcessingController.AddSentEBoxFolderToFavorites(folder: MAPIFolder);
const
// OlNavigationModuleType Enumeration
olModuleMail = 0;
// OlGroupType Enumeration
olFavoriteFoldersGroup = 4;
var
outlookApp: OleVariant;
navPane,
mainModule,
favGroup: Variant;
begin
if not Assigned(folder) then
exit;
try
outlookApp := CreateOleObject('Outlook.Application');
navPane := outlookApp.ActiveExplorer.NavigationPane;
mainModule := navPane.Modules
.GetNavigationModule(olModuleMail);
favGroup := mainModule.NavigationGroups
.GetDefaultNavigationGroup(olFavoriteFoldersGroup);
favGroup.NavigationFolders.Add(folder);
except
on E:Exception do
begin
// error handling
end;
end;
favGroup := Unassigned;
mainModule := Unassigned;
navPane := Unassigned;
outlookApp := Unassigned;
end;
Is it good enough? Or maybe there is better implementation? |
|
Posted 18 Oct, 2012 02:13:36
|
|
Top
|
|
Andrei Smolin
Add-in Express team
Posts: 18817
Joined: 2006-05-11
|
Mykhaylo Boreyko writes:
outlookApp := CreateOleObject('Outlook.Application');
This call is excessive in an add-in. Besides, it creates an "unsafe" Outlook.Application object. If you use it to access protected properties or methods (such as address fields or MailItem.Send) Outlook may fire a security warning. The recommended way is to use the "safe" Outlook.Application object accessible via OutlookApp property of the add-in module.
Andrei Smolin
Add-in Express Team Leader |
|
Posted 18 Oct, 2012 02:41:20
|
|
Top
|
|