Hi,
Whenever I try to remove or edit and update a contact in pocket outlook using .net compact framework I get the following error..
My code is like this:
================================================================================
========
public static void SetGroup(string iName, string group)
{
// Open an outlook session
OutlookSession outlookSession = new OutlookSession();
Contact contact = null;
// Retrieve the contacts from outlook
ContactCollection contactCollection = outlookSession.Contacts.Items;
bool isFound = false;
if (contactCollection != null)
{
if (contactCollection.Count > 0)
{
// Add the equals contacts a new.
for (int i = 0; i < contactCollection.Count; i++)
{
contact = contactCollection[i];
string inam = contact.Nickname;
if (inam == iName)
{
// Delete the current contact
//contactCollection.RemoveAt(i);
if (contact.Nickname != string.Empty && inam.StartsWith("="))
{
isFound = true;
break;
}
}
}
if (isFound)
{
contact.MiddleName = group;
contact.Update(); //THIS IS WHERE I GET THE ERROR
}
}
}
outlookSession.Dispose();
}
================================================================================
==============
Error:
==============
System.InvalidOperationException was unhandled
Message="Can't modify the item collection inside a foreach statement"
StackTrace:
at PimItemCollectionEnumerator.collection_ListChanged()
at Microsoft.WindowsMobile.PocketOutlook.PimItemCollection.RemoveAt()
at EqualizerLibrary.Util.SetGroupInOutlook()
at EqualizerUI.MyGroupsForm.mitChangeGroup_Click()
at System.Windows.Forms.MenuItem.onclick()
at System.Windows.Forms.Menu.ProcessMnuProc()
at System.Windows.Forms.Form.WnProc()
...
...
I was wondering if someone has a solution to the problem. It would be very nice if you could share the same with me.
Thanks a lot
Regards,
Khalid Naseem.
[email protected]
Whenever I try to remove or edit and update a contact in pocket outlook using .net compact framework I get the following error..
My code is like this:
================================================================================
========
public static void SetGroup(string iName, string group)
{
// Open an outlook session
OutlookSession outlookSession = new OutlookSession();
Contact contact = null;
// Retrieve the contacts from outlook
ContactCollection contactCollection = outlookSession.Contacts.Items;
bool isFound = false;
if (contactCollection != null)
{
if (contactCollection.Count > 0)
{
// Add the equals contacts a new.
for (int i = 0; i < contactCollection.Count; i++)
{
contact = contactCollection[i];
string inam = contact.Nickname;
if (inam == iName)
{
// Delete the current contact
//contactCollection.RemoveAt(i);
if (contact.Nickname != string.Empty && inam.StartsWith("="))
{
isFound = true;
break;
}
}
}
if (isFound)
{
contact.MiddleName = group;
contact.Update(); //THIS IS WHERE I GET THE ERROR
}
}
}
outlookSession.Dispose();
}
================================================================================
==============
Error:
==============
System.InvalidOperationException was unhandled
Message="Can't modify the item collection inside a foreach statement"
StackTrace:
at PimItemCollectionEnumerator.collection_ListChanged()
at Microsoft.WindowsMobile.PocketOutlook.PimItemCollection.RemoveAt()
at EqualizerLibrary.Util.SetGroupInOutlook()
at EqualizerUI.MyGroupsForm.mitChangeGroup_Click()
at System.Windows.Forms.MenuItem.onclick()
at System.Windows.Forms.Menu.ProcessMnuProc()
at System.Windows.Forms.Form.WnProc()
...
...
I was wondering if someone has a solution to the problem. It would be very nice if you could share the same with me.
Thanks a lot
Regards,
Khalid Naseem.
[email protected]







Sign In
Create Account

Back to top









