Can't delete custom contacts folder

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

Can't delete custom contacts folder
 
Oliver D.




Posts: 54
Joined: 2005-02-03
I am having the code below. However, the custom contacts folder is not being deleted. I tried .Delete() and .MoveTo().

Any help is appreciated> :-)

public static void DeleteContactsFolder(string folderName,_Application OutlookApp)
{
_NameSpace _namespace = null;
MAPIFolder contacts = null, myContacts = null, trashFolder=null;
try
{
_namespace = OutlookApp.GetNamespace("MAPI");
contacts = _namespace.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
trashFolder = _namespace.GetDefaultFolder(OlDefaultFolders.olFolderDeletedItems);
for(int i=1; i<=contacts.Folders.Count; i++)
{
if (contacts.Folders.Item(i).Name == folderName)
{
// contacts.Folders.Item(i).Delete();
contacts.Folders.Item(i).MoveTo(trashFolder);
break;
}
}
}
catch(Exception err)
{
AppHelper.PublishError(err,true);
}
finally
{
if (_namespace != null)
Marshal.ReleaseComObject(_namespace);
if (contacts != null)
Marshal.ReleaseComObject(contacts);
if (myContacts != null)
Marshal.ReleaseComObject(myContacts);
}
}
Posted 01 Apr, 2005 15:36:39 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Oliver.

I have just tested your code. All works properly.
Do you get any error messages when the folder is being deleted?
Posted 02 Apr, 2005 15:18:14 Top
Oliver D.




Posts: 54
Joined: 2005-02-03
No error messages. It loops through the folders, but does not move it to the trash (delete).

So, I assume the MoveTo(trashFolder) is the correct statement? If so, what is the Delete() supposed to do? (I can't seem to find a function for it :-))
Posted 04 Apr, 2005 11:50:55 Top
Oliver D.




Posts: 54
Joined: 2005-02-03
OK. The deleting works now. I had to set the Folder Description to ensure that Outlook does not add a number to it. It's weired, but now it works fine!
Posted 04 Apr, 2005 14:54:29 Top
Oliver D.




Posts: 54
Joined: 2005-02-03
Actually, I was wrong. It still doesn't work everytime. It seems to work sometimes only. Strange.

Any help is appreciated on this strange behavior. :-)
Posted 04 Apr, 2005 15:21:14 Top
Sergey Grischenko


Add-in Express team


Posts: 7187
Joined: 2004-07-05
Hi Oliver.

The fact is, that the following statement is case sensitive.

if (contacts.Folders.Item(i).Name == folderName)

Are you sure that a value of the folderName variable is set correctly?
I tested the MoveTo and Delete functions. They both work fine.
Posted 05 Apr, 2005 04:34:44 Top