473,757 Members | 7,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DeleteAllEntrie s()
Dim objFolder As Outlook.MAPIFol der
Dim origCount, numDeleted As Integer
Set objFolder = GetFolder(InstP refs.GetFolderP ath)
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 ("Successful ly 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 1535

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

Similar topics

0
2282
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. It is telling me that items is not a collection. I've tried everything I can think of, I've even copied the code from a few sources (had to add specific OOM in front of method names), Including Sues book, some code from www.outlookcode.com, and...
5
16829
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 and no files are deleted in the folder. The peculiarity of this issue is that the files/subfolders cannot be seen through the windows explorer either. I can only access/delete them through a command shell. Any ideas?
1
4289
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 collection and delete appointments from the items collection based on some business rules. However after I delete/remove items I am getting "index out of range" and/or "object has been moved or deleted" errors. Also, sometimes it seems that the...
3
4511
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 to record 250 and then i start getting the cast exception errors. Once i get one it continues until the last record which is 3500. It's almost like the connection dies after 250 records. OR even though the messageclass is "IPM.Contact".. could...
0
971
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 'Archive->2005 Mail' folder. But, it seems to make copies of existing email in the '2005 Mail' folder and I don't know why. My 'FOR NEXT" loop seems like it's right, so I'm not sure why it's doing that. Dim i As Integer Dim count As Integer Dim...
2
2812
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, Items.ReceivedTime is April 2005 Items.ReceivedTime is May 2005 Items.ReceivedTime is October 2005 Items.ReceivedTime is June 2005 I did some experiments and the following seems to explain how
1
2192
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 program loops through, reading each contact, it will randomly start throwing exceptions (usually a large batch at a time), therefore fails to read the contact. This is the current code snippet that I am using, although I have tried allsorts. I can't...
1
1775
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 an Outlook 2007 calendar item via an external program (eg. by Exchange Explorer or Exchange 2007 Web Services) I am unable to update that item in Outlook itself until I restart the application.
3
2180
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 application in C# and it worked fine, I added the OL reference and created the COM object with the following code:
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8737
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7286
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.