在Outlook加载项上保存例外

时间:2016-07-28 10:46:58

标签: c# outlook calendar save outlook-addin

我正在尝试以编程方式更改重复项(并进行例外处理)。

该项目是Outlook 2010 AddIn。

我尝试了以下代码,但经过几次保存后,代码退出calitm.Save()命令

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);
}

你有什么建议吗? Thnx你的时间......

1 个答案:

答案 0 :(得分:0)

如果您的代码存在,则意味着在您调用Save方法时会出现崩溃的情况。

您实际上需要尝试/捕获您的错误代码,以便您可以保存/重新抛出异常

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);
}