title: Update and cancel outlook appointment using ICS file
body: <p>I'm trying to create an application which will create, update and cancel an appointment on target user's outlook calendar using ICS file.
  I've successfully created the ICS file and send to target user's successfully for the first time.
  <strong>But I'm unable to edit and cancel the appointment through an ICS file.</strong>
  Here's my current code:-</p>
  
  <pre><code>private static byte[] CreateiCal(string subject, string location, DateTime startTime, DateTime endTime)
      {
          var a = new StringBuilder();
          var guid = Guid.NewGuid();
  
          a.Append("BEGIN:VCALENDAR\r\f");
          a.Append("VERSION:2.0\r\f");
          a.Append("PRODID:-//ince/events//NONSGML v1.0//EN\r\f");
          a.Append("BEGIN:VEVENT\r\f");
          a.Append(String.Format("DTSTART:{0}\r\f", GetFormatedDate(startTime)));
          a.Append(String.Format("DTEND:{0}\r\f", GetFormatedDate(endTime)));
          a.Append(String.Format("LOCATION:{0}\r\f", location));
          a.Append(String.Format("UID:{0}\r\f",guid));
          a.Append(String.Format("SUMMARY:{0}\r\f", subject));
          a.Append(String.Format("DESCRIPTION:{0}\r\f", subject));
  
  
          a.Append("BEGIN:VALARM\r\f");
          a.Append("TRIGGER:-PT15M\r\f");
          a.Append("REPEAT:2\r\f");
          a.Append("DURATION:PT15M\r\f");
          a.Append("ACTION:DISPLAY\r\f");
          a.Append("DESCRIPTION:Reminder\r\f");
  
          a.Append("END:VALARM\r\f");
          a.Append("END:VEVENT\r\f");
          a.Append("END:VCALENDAR\r\f");
          byte[] b = Encoding.ASCII.GetBytes(a.ToString());
          return b;
      }
  
      private static string GetFormatedDate(DateTime date)
      {
          return String.Format("{0}{1}{2}T{3}{4}00Z", date.ToUniversalTime().Year, date.ToUniversalTime().Month.ToString("00"), date.ToUniversalTime().Day.ToString("00"), date.ToUniversalTime().Hour.ToString("00"), date.ToUniversalTime().Minute.ToString("00"));
      }
  
      private String CreateBody(String title, String description, String location, DateTime startTime, DateTime endTime)
      {
          const String successStyle = ".success{color: #333333;font-family: Century Gothic, Arial;font-size:1.4em;margin-top:5px;margin-bottom:5px;}";
          const String standardStyle = ".standard{color: #333333;font-family: Century Gothic, Arial;font-size:1.0em}";
          const String reminderStyle = ".reminderStyle{color: red;font-family: Century Gothic, Arial;font-size:1.0em;font-variant:italic;margin-top:2px;margin-bottom:2px;}";
          const String contentsStyle = ".contentsTable{color: #333333;font-family: Century Gothic, Arial;font-size:1.0em;border-collapse:collapse;border-spacing:0px;padding:0px;margin:0px;} .contentsTable &gt; td {padding-right:5px;}";
          var b = new StringBuilder();
          b.Append(String.Format("&lt;style&gt;{0} {1} {2} {3}&lt;/style&gt;", successStyle, standardStyle, contentsStyle, reminderStyle));
          b.Append(String.Format("&lt;div class=\"standard\"&gt;You have successfully registered for the following event&lt;/div&gt;"));
          b.Append(String.Format("&lt;div class=\"success\"&gt;{0}&lt;/div&gt;", title));
          b.Append(String.Format("&lt;div class=\"reminderStyle\"&gt;Please click on the calendar invitation to add this appointment to your calendar.&lt;/div&gt;"));
          b.Append(String.Format("&lt;table class=\"contentsTable\"&gt;"));
          b.Append(String.Format("&lt;tr class=\"standard\"&gt;&lt;td&gt;Time&lt;/td&gt;&lt;td&gt;{0} - {1}&lt;/td&gt;&lt;/tr&gt;", startTime, endTime));
          b.Append(String.Format("&lt;tr class=\"standard\"&gt;&lt;td&gt;Location&lt;/td&gt;&lt;td&gt;{0}&lt;/td&gt;&lt;/tr&gt;", location));
          b.Append(String.Format("&lt;tr class=\"standard\"&gt;&lt;td&gt;Description&lt;/td&gt;&lt;td&gt;{0}&lt;/td&gt;&lt;/tr&gt;", description));
          b.Append(String.Format("&lt;/table&gt;"));
          return b.ToString();
      }
  
      public void SendAppointment(string from, string to, string title, string body, DateTime startTime, DateTime endTime, String location)
      {
          try
          {
              SmtpClient smtpClient = new SmtpClient();
              MailMessage message = new MailMessage();
  
  
              smtpClient.Host = "my.smtp.server";
  
              smtpClient.Port = 25;
  
              smtpClient.EnableSsl = false;
  
              smtpClient.UseDefaultCredentials = true;
  
  
              message.From = new MailAddress(from);
              message.To.Add(new MailAddress(to));
              message.Subject = "Successfully registered";
              string result = "Sample text";
  
              message.Body = "&lt;html&gt;&lt;head&gt;&lt;body&gt;" + CreateBody(title, body, location, startTime, endTime) +  "&lt;/body&gt;&lt;/head&gt;&lt;/html&gt;";
              message.IsBodyHtml = true;
  
              byte[] attachment = CreateiCal(title, location, startTime, endTime);
              var ms = new MemoryStream(attachment);
              message.Attachments.Add(new Attachment(ms, "eventappointment.ics", "text/calendar"));
  
              smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
  
              smtpClient.Send(message);
  
              string sMessage = "Email sent.";
  
              Console.WriteLine(sMessage);
  
          }
          catch (Exception ex)
          {
              Console.WriteLine("Couldn't send the mail!" + Environment.NewLine + ex.Message);
          }
  
  
      }
  </code></pre>
  
  <p>And in my main method I made a call as given below:-</p>
  
  <pre><code>DateTime startTime = new DateTime(2017, 08, 29, 14, 15, 0);
  DateTime endTime = new DateTime(2017, 08, 30, 16, 35, 0);
  CreateICS objCreateICS = new CreateICS();
  objCreateICS.SendAppointment("fistname.lastname@server.com", "person2.surname@server.com", "Title", "Subject", startTime, endTime, "Location");
  Console.ReadLine();
  </code></pre>
  
  <p>Now I want to update and cancel the same appointment through ICS.
  I've tried to implement solution using below links, but nothing works :</p>
  
  <p><a href="https://stackoverflow.com/questions/2654743/cancel-outlook-meeting-requests-via-mailmessage-in-c-sharp">Cancel Outlook meeting</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4957504/replace-existing-outlook-calendar-appointment">replace-existing-outlook-calendar-appointment</a></p>
  
  <p>Can anyone please guide me on how to do this?
  Thanks in advance.</p>