Как обновить icalender программно

Я хочу отправить приглашение на собрание, используя приложение C#, поэтому я использовал библиотеку dday.ical. с помощью библиотеки ical я создаю файл.ics, но теперь я хочу обновить свою уже созданную встречу, которую я ищу в Интернете, и обнаружил, что мы можем обновить календарь с помощью uid, но когда я создаю новый cal с тем же uid и запускаю, мой существующий файл.ics заменяет с новым файлом он не сливается с существующим файлом

Ниже мой код

private iCalendar CreateOneTimeCalendarEvent(string title,Dictionary<string,string> attendees, string body, DateTime startDate, double duration, string location, string organizer,
                                     string eventId, bool allDayEvent)
        {
           var iCal = new iCalendar
            {
                Method = "PUBLISH", //PUBLISH
                Version = "2.0"
            };

         //Creating event evt    
            var evt = iCal.Create<Event>();
            //Title to event
            evt.Summary = title;

            //Start time to event
            evt.Start = new iCalDateTime(startDate.Year,
                                         startDate.Month, startDate.Day, startDate.Hour,
                                         startDate.Minute, startDate.Second);


            // Description to event
            evt.Description = body;

            // Location to event
            evt.Location = location;

            //Check for All day event
            evt.IsAllDay = allDayEvent;

            //End time for event
            if (!allDayEvent)
            {
                // Duration to event
                evt.Duration = TimeSpan.FromHours(duration);

            }

            //Event unique identifier id
            evt.UID = new Guid().ToString();

            //Orgnizer to event
            if (!String.IsNullOrEmpty(organizer))
            {
                evt.Organizer = new Organizer(organizer);
            }
            else
            {
                throw new Exception("Organizer provided was null");
            }
            var attendes = new List<IAttendee>();

            foreach ( var atten in attendees)
            {

                IAttendee attendee1 = new DDay.iCal.Attendee("MAILTO:"+atten.Key)
                {
                    Role = atten.Value
                };
                attendes.Add(attendee1);

            }

            //Adding attendees into event

            evt.Attendees = attendes;


            if (!String.IsNullOrEmpty(eventId))
            {
                evt.UID = eventId;
            }

            //Creating Alarm for event
            var alarm = new Alarm
            {
                Duration = new TimeSpan(0, 15, 0),
                Trigger = new Trigger(new TimeSpan(0, 15, 0)),
                Action = AlarmAction.Display,
                Description = "Reminder"
            };


            evt.Alarms.Add(alarm);

            // Save into calendar file.
            var serializer = new iCalendarSerializer(iCal);

          //   serializer.SerializeToString(iCal);

            serializer.Serialize(iCal, "OneTimeCalendarEvent.ics");

            return iCal;
        }

и моя вторая проблема, когда я использовал smtp с приложенным файлом ics, он просто прикрепил файл к почте, а не работал как событие запроса календаря. Ниже приведен мой код:

 static void Main(string[] args)
        {
            Dictionary<string,string> attendees =new Dictionary<string,string>();
            attendees.Add("abc11@gmail.com", "REQ-PARTICIPANT");
            attendees.Add("abc21@gmail.com", "OPT-PARTICIPANT");

            attendees.Add("abc32@gmail.com", "OPT-PARTICIPANT");
            attendees.Add("abc43@gmail.com", "REQ-PARTICIPANT");
            attendees.Add("abc54@gmail.com", "OPT-PARTICIPANT");

            Program obj = new Program();
           iCalendar iCal= obj.CreateOneTimeCalendarEvent("Gnd Party", attendees,
                "Every budy shawa shawa", 
                DateTime.Now, 30.0, "Pune", 
                "rajendra.b", 
                Guid.NewGuid().ToString(),

                false);


           MailMessage message =obj.initMailMessage();

            //Add the attachment, specify it is a calendar file.
            System.Net.Mail.Attachment attachment =
            System.Net.Mail.Attachment.CreateAttachmentFromString(
            iCal.ToString(), new ContentType("text/calendar"));
            attachment.TransferEncoding = TransferEncoding.Base64;
            attachment.Name = "EventDetails.ics"; //not visible in outlook
            message.Attachments.Add(attachment);
            sendMailMessage(message);


        }

способ отправки почты:

private static void sendMailMessage(MailMessage mailMessage)
{

    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");


    SmtpServer.Port = 587;
    SmtpServer.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "@12345");
    SmtpServer.EnableSsl = true;

    SmtpServer.Send(mailMessage);
    Console.WriteLine("mail send");
    Console.ReadLine();
}

0 ответов

Другие вопросы по тегам