PC Review


Reply
Thread Tools Rate Thread

deleting contactitems

 
 
HARI
Guest
Posts: n/a
 
      19th Mar 2008
Hi!

I'm trying to delete a few (well about 1000) contact items from my
default contacts folder.

I do it with something like that in VB.NET:

Dim oOtk As New Outlook.Application
Dim NS As Outlook.NameSpace = oOtk.GetNamespace("MAPI")
Dim fContacts As Outlook.Folder =
NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
anz = fContacts.Items.Count
For i As Integer = anz To 1 Step -1
fContacts.Items.Remove(i)
Next

This works fine when I try the same in Outlook VBA.
In my VB.NET Application it also seems to run at first, deleting some
100 of the contacts but there always occurs an exception before
finishing it:

"System.Runtime.InteropServices.COMException (0x80040305): Die Anzahl
der Elemente, die gleichzeitig geöffnet werden können, wurde vom
Serveradministrator begrenzt. Schließen Sie zunächst geöffnete
Nachrichten, oder entfernen Sie Anhänge und Bilder von ungesendeten
Nachrichten, die Sie gerade verfassen.
bei
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack, Boolean IgnoreReturn)
bei
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean
IgnoreReturn)
bei Tel2Otk2007.frmTel2Otk2007.myBGW_DoWork(Object sender,
DoWorkEventArgs e)"

Sorry for the German Message which says something like there is a
restriction of the number of elements which can be open simultaniously
and that I should close some opened Messages. But I don't open any, I
just want to delete them.

Do you have any Idea how to handle with that problem?

Cheers,

HARI

 
Reply With Quote
 
 
 
 
Brian Tillman
Guest
Posts: n/a
 
      19th Mar 2008
HARI <(E-Mail Removed)> wrote:

> I'm trying to delete a few (well about 1000) contact items from my
> default contacts folder.
>
> I do it with something like that in VB.NET:


Ask in the programming newsgroups. microsoft.public.outlook.program_vba
would be a good place to start.
--
Brian Tillman [MVP-Outlook]

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      20th Mar 2008
By accessing them you are opening them. Accessing any property of an item or
accessing the item itself does open it behind the scenes.

Is this against an Exchange server or a PST file? My guess is Exchange. By
default Exchange has a limit of about 255 open RPC channels. Until your code
loop finishes and the procedure ends each iteration of your loop
instantiates objects that don't go out of scope until the procedure ends.

Each iteration you have gets fContacts.Items and then uses the Remove()
method. First of all, get fContacts.Items as a collection and use that
instead of using the dot operator each time. Each dot operator instantiates
an instance of the Items collection each time through the loop.

If that doesn't help enough you have a couple of alternatives. You can get
the item explicitly and call its Delete() method and then call
Marshal.ReleaseComObject() on each item you get to explicitly release it.
You can also call you loop procedure multiple times to delete say 75 - 90
items at a time until they all are deleted.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"HARI" <(E-Mail Removed)> wrote in message
news:375fca1d-222e-46c2-8cd3-(E-Mail Removed)...
Hi!

I'm trying to delete a few (well about 1000) contact items from my
default contacts folder.

I do it with something like that in VB.NET:

Dim oOtk As New Outlook.Application
Dim NS As Outlook.NameSpace = oOtk.GetNamespace("MAPI")
Dim fContacts As Outlook.Folder =
NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
anz = fContacts.Items.Count
For i As Integer = anz To 1 Step -1
fContacts.Items.Remove(i)
Next

This works fine when I try the same in Outlook VBA.
In my VB.NET Application it also seems to run at first, deleting some
100 of the contacts but there always occurs an exception before
finishing it:

"System.Runtime.InteropServices.COMException (0x80040305): Die Anzahl
der Elemente, die gleichzeitig geöffnet werden können, wurde vom
Serveradministrator begrenzt. Schließen Sie zunächst geöffnete
Nachrichten, oder entfernen Sie Anhänge und Bilder von ungesendeten
Nachrichten, die Sie gerade verfassen.
bei
Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object
o, Type objType, String name, Object[] args, String[] paramnames,
Boolean[] CopyBack, Boolean IgnoreReturn)
bei
Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean
IgnoreReturn)
bei Tel2Otk2007.frmTel2Otk2007.myBGW_DoWork(Object sender,
DoWorkEventArgs e)"

Sorry for the German Message which says something like there is a
restriction of the number of elements which can be open simultaniously
and that I should close some opened Messages. But I don't open any, I
just want to delete them.

Do you have any Idea how to handle with that problem?

Cheers,

HARI

 
Reply With Quote
 
HARI
Guest
Posts: n/a
 
      25th Mar 2008
Hi Ken!

That was the information I needed. Especially the
Marshal.ReleaseComObject() seems to have done it.

Thanks a lot!

HARI

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the ContactItems in a DistListItem? =?Utf-8?B?T2N0b3B1c1RodQ==?= Microsoft Outlook Program Addins 3 11th Nov 2006 08:18 PM
How to get the ContactItems in a DistListItem? =?Utf-8?B?T2N0b3B1c1RodQ==?= Microsoft Outlook Form Programming 0 9th Nov 2006 05:14 PM
Add ContactItems to DLItem with VBS Christoph Fricke Microsoft Outlook VBA Programming 8 10th May 2006 06:03 PM
Linking attendees to ContactItems nargisb@infotracsolutions.com Microsoft Outlook Program Addins 0 27th Mar 2006 05:02 PM
ContactItems from a DistList DUS Microsoft Outlook VBA Programming 1 14th Feb 2005 07:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:06 PM.