1

I want to send meeting request using C# application so I used dday.ical library. by using ical library I create .ics file but now I want to update my already created meeting I search on internet and I found we can update calendar with uid but when I create new cal with same uid and run, my existing .ics file replace with new file it didn't merge with existing file

Below is my code

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

and my second problem is when I used smtp with attached ics file it just attached file to mail not work as like calendar request event Below is my code:

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

method to send mail:

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();
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
user1619672
  • 259
  • 1
  • 7
  • 15

0 Answers0