deleting contactitems

  • Thread starter Thread starter HARI
  • Start date Start date
H

HARI

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
 
HARI said:
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.
 
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.




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
 
Hi Ken!

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

Thanks a lot!

HARI
 
Back
Top