Unable to delete MAPI folder (MapiFolder.Delete)

  • Thread starter Thread starter jules
  • Start date Start date
J

jules

Hi.
I am a using Outlook 2000 on Windows XP and I am programming with VB6.
Currently I'm facing a strange problem with deleting a mapi folder
programmtically.
Situation: There are around 50 mapi folders (Fold01 - Folder48) that
have been created initially. Each of these folders does contain one!
subfolder. When Outlook starts, my COM-Adding should delete each
subfolder of each toplevel folder. This is done with
TopFolder.Subfolder.Delete. Subfolder of couse is of type MapiFolder.

This seems to work for the first 20 folders but when it comes to the
21st Outlook throws an error saying:
"Unable to delete this folder. Right-click the folder, and then click
Properties to check your permissions for the folder. See the folder
owner or your administrator to change your permissions."

According to this error message I've got some permission problem.
Unfortunately this not true because I did (more than once) randomize
the order in which each of the subfolders should be removed. Strangly
enough it is always the 21st folder that refuses to remove.
I did then try to remove these remaining folders manually. Same error
message here.


Here's a code snippet:

set WGFolders =
OutlooContext.MainFolder.AllWo­rkGroupFolder.WorkGroupFolders­;
For i = 1 To WGFolders.Count
Set soWGFolder = WGFolders.Item(i)
If soWGFolder.WorkGroup.name = primaryWorkGroup Then


Set soWiFolder = soWGFolder
Call soWiFolder.SuspendFolder.Delet­e
'!!!!!!!!!!!!!!!!!!!!!!!!!!
End If


' .....
Next


Please keep in mind that this works with the first 20 MapiFolders and
the order does not seem to matter.


You see I'm using a up-counting loop but also tried with a for each
construct.
SuspendFolder is as I mentioned earlier the subfolder that should be
deleted and is of type MapiFolder!
Another strange thing is when I display that error message with
Err.Number I do always face a different error number.


Does anybody ever faced a similar problem?
Any suggestions, hints, tips,....?

Thanx in advance and best regards
 
Deleting a folder changes the number of items in the collection. Instead of
looping from 1 to Count, go from Count down to 1:

For i = WGFolders.Count to 1 step -1

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Hi.
I am a using Outlook 2000 on Windows XP and I am programming with VB6.
Currently I'm facing a strange problem with deleting a mapi folder
programmtically.
Situation: There are around 50 mapi folders (Fold01 - Folder48) that
have been created initially. Each of these folders does contain one!
subfolder. When Outlook starts, my COM-Adding should delete each
subfolder of each toplevel folder. This is done with
TopFolder.Subfolder.Delete. Subfolder of couse is of type MapiFolder.

This seems to work for the first 20 folders but when it comes to the
21st Outlook throws an error saying:
"Unable to delete this folder. Right-click the folder, and then click
Properties to check your permissions for the folder. See the folder
owner or your administrator to change your permissions."

According to this error message I've got some permission problem.
Unfortunately this not true because I did (more than once) randomize
the order in which each of the subfolders should be removed. Strangly
enough it is always the 21st folder that refuses to remove.
I did then try to remove these remaining folders manually. Same error
message here.


Here's a code snippet:

set WGFolders =
OutlooContext.MainFolder.AllWo­rkGroupFolder.WorkGroupFolders­;
For i = 1 To WGFolders.Count
Set soWGFolder = WGFolders.Item(i)
If soWGFolder.WorkGroup.name = primaryWorkGroup Then


Set soWiFolder = soWGFolder
Call soWiFolder.SuspendFolder.Delet­e
'!!!!!!!!!!!!!!!!!!!!!!!!!!
End If


' .....
Next


Please keep in mind that this works with the first 20 MapiFolders and
the order does not seem to matter.


You see I'm using a up-counting loop but also tried with a for each
construct.
SuspendFolder is as I mentioned earlier the subfolder that should be
deleted and is of type MapiFolder!
Another strange thing is when I display that error message with
Err.Number I do always face a different error number.


Does anybody ever faced a similar problem?
Any suggestions, hints, tips,....?

Thanx in advance and best regards
 
Thanx for your suggestion.
But this did not help me either.
If the total count of MAPI folders was 20, why didn't I face this error
message?

I do not remove a folder from that collection but a subfolder from a
folder of that collection. So the total count of 'toplevel' folders in
that collection remains constant.

Another thing is that when I 'manually' rename a folder I'm able to
'manually' delete this folder from within outlook.
Any other suggestions?

Best regards...
 
Oh, sorry, didn't notice that you are deleting the subfolders.
Youy might be running into the 255 RPC channels/process limit - each MAPI
object (such as message, folder, etc) opens an RPC channel.
It looks like you are using your own wrappers to store Outlook folders. Try
to store the folder entry ids only and only retrieve them as necessary using
Namespace.GetFolderFromID.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top