473,404 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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 1504

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason Ferree | last post by:
I posetd this in one group, but got no response, so I'll try it in this one. I am trying to loop through all messages in the inbox. To do something, in my case, look for and save attachments....
5
by: Rosa | last post by:
Hi, I'm trying to clear the TIF on Windows XP programmatically with the below code. This code works fine on any folder but the TIF. For some reason the atEnd() statements always defaults to true...
1
by: Crash | last post by:
Windows XP SP2 C# .NET v1.1 Outlook 2003 {via Office 11.0 PIA} I'm manipulating Outlook's calendar via OLE automation from my C# application. I would like to iterate through the calendar items...
3
by: Chris Thunell | last post by:
I am looping through a Public Folder in our Exchange 2003 server system and i keep getting invalid cast exceptions although the Message Class is set correctly for each item. It works until i get...
0
by: richardkreidl | last post by:
I setup the code below to fire off from an Outlook rule when an email arrives in the 'Inbox'. The code does work to a point. It does copy email messages when they arrive in the 'Inbox' to the...
2
by: hsuntn | last post by:
I am grabbing Outlook MailItems using the Items property on my Outlook inbox. When I iterate through them, I notice that they are not ordered in ReceivedTime or CreationTime order. For example, ...
1
by: philmarsay | last post by:
I have some code that loops through all contacts in a contact folder (approx 3000), reads some details from each contact and uses that information to perform various functions. However, as the...
1
by: =?Utf-8?B?R29yZG9uUw==?= | last post by:
Hello, I am unsure which group this should go under so have placed it on the general, if anybody can suggest a more appropriate group that would be great. I have a problem whereby if I update...
3
by: Bruno Vignola | last post by:
Good Morning all, I need to interoperate with the Calendar of MS Outlook 2003 (inserting, retrieving, listing events, etc. etc.) from an ASP.NET application; I first developed a simple windows...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.