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);
}
} |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
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? |
|
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 :-)) |
|
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! |
|
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. :-) |
|
Sergey Grischenko
Add-in Express team
Posts: 7235
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.
|
|