470,613 Members | 1,498 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,613 developers. It's quick & easy.

Deleting all items in an Outlook folder with VB.NET

Hello,

I'm writing an app that involves deleting all the items in a specified
Outlook folder regardless of item type (i.e. Contacts, Tasks, etc.).
This code was ported from VBA where it worked okay, but now in .NET it
is exceedingly too slow when attempting to delete large collections
(roughly 10,000). It is on the order of 10 items deleted every 30
seconds. My function is as follows:

Private Sub DeleteAllEntries()
Dim objFolder As Outlook.MAPIFolder
Dim origCount, numDeleted As Integer
Set objFolder = GetFolder(InstPrefs.GetFolderPath)
origCount = objFolder.Items.Count

For i = objFolder.Items.Count To 1 Step -1
objFolder.Items.Item(i).Delete
numDeleted = origCount - objFolder.Items.Count
If numDeleted Mod 100 = 0 Then
UpdateProgress ("Deleted " & numDeleted & " items of " & _
origCount & ".")
End If
Next
UpdateProgress ("Successfully deleted " & numDeleted & " items.")
End Sub

This code is running behind a form and fires after the user has pressed
a "Begin" button. The UpdateProgress() call refreshes the form and
updates the user on the progress of the deletion. FYI, I have also
tried using objFolder.Items.Remove(i) in place of
objFolder.Items.Item(i).Delete, but the speed of the process does not
change. I also briefly considered deleting the entire folder and then
re-adding it, but this method is moot if the user has selected one of
the default Outlook folders (which they are able to do). I think I
read somewhere that CDO is supposed to be apt at handling this kind of
thing, but that CDO is not explicitly supported in .NET? Any help or
insight is much appreciated.

Kindest regards,
Steve

Nov 21 '05 #1
0 1380

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jason Ferree | last post: by
reply views Thread by richardkreidl | last post: by
2 posts views Thread by hsuntn | last post: by
1 post views Thread by =?Utf-8?B?R29yZG9uUw==?= | last post: by
3 posts views Thread by Bruno Vignola | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.