从代码中分配Outlook约会重复类型

时间:2015-09-29 07:31:58

标签: c# asp.net outlook-addin office-addins

我正在尝试通过代码在Outlook中添加约会。 “Outlook.AppointmentItem”对象有一个名为“GetRecurrencePattern()。RecurrenceType”的属性。当我尝试将此属性设置为“OlRecurrenceType.olRecursDaily”时,它会自动转换为“OlRecurrenceType.olRecursWeekly”。

这是我的代码:

       Outlook.AppointmentItem oMeet;
Meeting Meet;
Hashtable htrecc = GetReccuranceTable(strRec);
  if (Meet.recctype.Substring(0, 3) == "day")
  {
     oMeet.GetRecurrencePattern().RecurrenceType = OlRecurrenceType.olRecursDaily;
    OlRecurrenceType pattern2 = oMeet.GetRecurrencePattern().RecurrenceType;
     string rectype = pattern2.ToString();
     oMeet.GetRecurrencePattern().Interval = Convert.ToInt32(htrecc["Interval"]);
     if (string.Equals("no", htrecc["Occurence"]))
         oMeet.GetRecurrencePattern().NoEndDate = true;
     else
          if (!string.IsNullOrEmpty(Convert.ToString(htrecc["Occurence"])))
              oMeet.GetRecurrencePattern().Occurrences = Convert.ToInt32(htrecc["Occurence"]);
          else
              oMeet.GetRecurrencePattern().PatternEndDate = Meet.EndTime;
    }

字符串“rectype”返回值“ olRecursWeekly ” 如果我在某个地方出错,请建议。

1 个答案:

答案 0 :(得分:1)

每次调用GetRecurrencePattern()时,都会返回一个全新的RecurrentPattern COM对象。不要每次都调用GetRecurrencePattern() - 调用一次,缓存值,并在代码中的任何地方使用它

 Outlook.RecurrencePattern pattern = oMeet.GetRecurrencePattern();
 pattern.RecurrenceType = OlRecurrenceType.olRecursDaily;
    OlRecurrenceType pattern2 = pattern.RecurrenceType;
     string rectype = pattern2.ToString();
     pattern.Interval = Convert.ToInt32(htrecc["Interval"]);
     if (string.Equals("no", htrecc["Occurence"]))
         pattern.NoEndDate = true;
     else
          if (!string.IsNullOrEmpty(Convert.ToString(htrecc["Occurence"])))
              pattern.Occurrences = Convert.ToInt32(htrecc["Occurence"]);
          else
              pattern.PatternEndDate = Meet.EndTime;