0

I am trying to programmatically change items of a recurrence (and make the exceptions).

The project is an Outlook 2010 AddIn.

I tried the following code but after a couple of saves the code exited at the calitm.Save() command

extracted ="somelocation"  

//that's a fancy way to iterate on a list of appointment items
for (int i = 0; i < filterAppointmentsToChangeLocation.RecordCount; i++)
{
    int selrow = 1
    var calitm = filterAppointmentsToChangeLocation.data[selrow].GetOlAppointment();
    //this returns an appointmentitem that is associated with a form 
    //that contains the location property

    calitm.UserProperties["location"].Value = extracted;
    calitm.Save();

    Marshal.ReleaseComObject(calitm);
}

Do you have any suggestions? Thnx for your time...

Benjamin Soulier
  • 2,223
  • 1
  • 18
  • 30

1 Answers1

0

If your code exists it means something is crashing during your call to your Save method.

You actually need to try/catch your faulting code so that you can save/rethrow your exception

for (int i = 0; i < filterAppointmentsToChangeLocation.RecordCount; i++)
{
    int selrow = 1
    var calitm = filterAppointmentsToChangeLocation.data[selrow].GetOlAppointment();

    try
    {
        calitm.UserProperties["location"].Value = extracted;
        calitm.Save();
    }
    catch (Exception e)
    {
        // save, output or retrhow your exception.
        System.IO.File.WriteAllText (@"C:\somepath\error.txt", e.Message);
    }
    Marshal.ReleaseComObject(calitm);
}
Benjamin Soulier
  • 2,223
  • 1
  • 18
  • 30
  • what do you mean save,output or rethrow your exception. what will each method do?Can I retry saving? it is rather important that save should be performed on each item – Kefalas Savvas Jul 28 '16 at 12:35
  • Have a look here http://stackoverflow.com/questions/14973642/how-using-try-catch-for-exception-handling-is-best-practice to see what you can do with exception handing; you can try to replay your save, or stop your for loop by rethrowing the exception – Benjamin Soulier Jul 28 '16 at 13:17