private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule) { CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"), rrule)); DateCollection date = pattern.GenerateOccurrences(start, endBy); return((uint)date.Count); }
private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule) { // ExStart:GetOccurrenceCountMonthlyEndAfterNoccurrences CalendarRecurrence pattern = new CalendarRecurrence(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"), rrule)); DateCollection dates = pattern.GenerateOccurrences(start, endBy); return (uint)dates.Count; // ExEnd:GetOccurrenceCountMonthlyEndAfterNoccurrences }
// ExStart:GeneratingOccurrencesFromRecurrencePatterns public static void GetOccurences() { // The path to the File directory string dataDir = RunExamples.GetDataDir_KnowledgeBase(); string tempFileName = dataDir + "Sample.pst"; Appointment appointment = CreateAppointment(); MailMessage mailMessage = CreateMessage(); AlternateView alternateView = appointment.RequestApointment(); mailMessage.AddAlternateView(alternateView); MapiMessage mapiMessage = MapiMessage.FromMailMessage(mailMessage); using (PersonalStorage pst = PersonalStorage.Create(tempFileName, FileFormatVersion.Unicode)) { FolderInfo folder = pst.RootFolder.AddSubFolder("Calendar"); folder.AddMessage(mapiMessage); } using (PersonalStorage pst = PersonalStorage.FromFile(tempFileName)) { var folder = pst.RootFolder.GetSubFolder("Calendar"); foreach (MessageInfo messageInfo in folder.GetContents()) { MapiMessage message = pst.ExtractMessage(messageInfo); MapiCalendar meeting = (MapiCalendar)message.ToMapiMessageItem(); using (MemoryStream memoryStream = new MemoryStream()) { meeting.Save(memoryStream); string s = StreamToString(memoryStream); CalendarRecurrence recurrencePattern = new CalendarRecurrence(s); DateCollection occurrences = recurrencePattern.GenerateOccurrences(); foreach (DateTime occurrence in occurrences) { Console.WriteLine("{0}", occurrence); } } } } File.Delete(tempFileName); }