在Outlook中为多个日历添加约会

时间:2015-01-06 16:34:35

标签: c# calendar outlook outlook-addin

我在Visual Studio 2010中创建了一个outlook AddIn。

我有两个Outlook日历:1)默认交换日历和2)个人时间跟踪日历。我有一个表单区域,显示帐号以跟踪我的时间,具体取决于任务。

我想做的是如果约会在我的个人日历中,我想将约会添加到我的时间跟踪日历中。

我试过这个:

var outlook = new Application();
var appt = OutlookItem as AppointmentItem;

if (appt == null)
    return;

try
{

    if (!string.IsNullOrEmpty(txtbxCapNum.Text))
    {
        if (appt.UserProperties.Find(Constants.CAPITAL_NUMBER) == null)
        {
            appt.UserProperties.Add(Constants.CAPITAL_NUMBER, OlUserPropertyType.olText);
        }

        appt.UserProperties[Constants.CAPITAL_NUMBER].Value = txtbxCapNum.Text;
    }


    if (!(outlook.Application.ActiveExplorer().CurrentFolder).Name.Equals(Constants.TIME_TRACKING_CALENDAR) && chbxInclude.Checked)
    {

        GetTimeTrackingCalendar(outlook).Items.Add(appt);
    }

    appt.Save();
}
catch (System.Exception ex)
{
    MessageBox.Show(ex.Message);
}

其中GetTimeTrackingCalendar定义为:

public static MAPIFolder GetTimeTrackingCalendar(Application outlook )
{
    MAPIFolder result = null;
    MAPIFolder calendars = (MAPIFolder)outlook.ActiveExplorer().Session.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
    for (int i = 1; i <= calendars.Folders.Count; i++)
    {
        if (calendars.Folders[i].Name != Constants.TIME_TRACKING_CALENDAR) continue;
        result = calendars.Folders[i];
        break;
    }
    return result;
}

但是,save方法返回以下不明确的错误:

=============================================== ==============================

无法完成操作。一个或多个参数值无效。

任何人都知道什么参数无效,甚至知道如何确定哪个参数无效?

谢谢,BillN

1 个答案:

答案 0 :(得分:0)

循环访问Namerspace.Stores集合,找到您需要的商店,并使用Store.GetDefaultFolder(olFolderCalendar)打开该商店的默认CXalendar文件夹。

相关问题