4

I have created appointment using the below code:

MailMessage mmMessage = new MailMessage();
System.Net.Mime.ContentType typeCalendar = new System.Net.Mime.ContentType("text/calendar");

//  Add parameters to the calendar header
typeCalendar.Parameters.Add("method", "REQUEST");
typeCalendar.Parameters.Add("name", "meeting.ics");

//Create the Body in VCALENDAR format  
string strCalDateFormat = "yyyyMMddTHHmmssZ";
string strBodyCalendar = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:(GMT-06.00) Central Time (US & Canada)\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{7}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:{10}\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";

string strUID = Session["ApptID"].ToString() + "@youremailaddress.com";
strBodyCalendar = string.Format(strBodyCalendar, dtStart.ToUniversalTime().ToString(strCalDateFormat), dtEnd.ToUniversalTime().ToString(strCalDateFormat), strLocation, strOrganizerName, strOrganizerEmail, strUID, strSummary, strSubject,DateTime.Now.ToUniversalTime().ToString(strCalDateFormat), macAttendeeList.ToString(),0);

AlternateView viewCalendar = AlternateView.CreateAlternateViewFromString(strBodyCalendar, typeCalendar);
viewCalendar.TransferEncoding = TransferEncoding.SevenBit;

mmMessage.AlternateViews.Add(viewCalendar);

Please guide me as how to delete the appointment created using the above code.

Now using the similar body i.e. strBodyCalendar I have to update the category of the outlook from the c# code itself.

I am passing \r\nCATEGORIES:MEETING and I have defined MEETING Category in BLUE color in my OUTLOOK.

Still after adding the appointment, the color or category is not updated.

Thank you for your help.

Please guide through.

Ruchi
  • 1,238
  • 11
  • 32
  • 1
    It looks like this code creates an email with an attached calendar event, which is not the same thing as adding an event to a calendar. To delete the appointment, wouldn't you need to interface with the calendar you added the attached calendar event to? – neontapir Jul 11 '12 at 18:58
  • You are creating a mailmessage that contains a meeting request that Outlook will show in the recievers calendar, at the best you might be able to cancel that request (or send an update that the meeting has been canceled) but I don't think that will automatically remove the event. For more info you should have a look at the iTIP RFC (http://www.ietf.org/rfc/rfc2446.txt), you might find what you need there. – Karl-Johan Sjögren Jul 11 '12 at 20:25
  • Is it possible to store the guid's somewhere in the database used to create the request and by any means comparing that stored guid would be the way to delete particular appointment in outlook???? – Ruchi Jul 12 '12 at 14:45

2 Answers2

3

When you are framing the appointment using Vcalendar,

You need to change the below attributes

  1. Method:Cancel

  2. UID should be same which you provided while creating appointment.

  3. Sequence should be same.

  4. Status should be changed from Confirmed To cancelled.

If you need any help related to the same, please paste your Vcalendar code below.

Ruchi
  • 1,238
  • 11
  • 32
0
Microsoft.Office.Interop.Outlook.Application OlApp = new 
Microsoft.Office.Interop.Outlook.Application();
NameSpace OlNamspace = OlApp.GetNamespace("MAPI");
MAPIFolder AppointmentFolder = 
OlNamspace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);

Items calendarItems = AppointmentFolder.Items;

AppointmentItem item = calendarItems["Subject/Item Name"] as 
AppointmentItem;

item.Delete();
MessageBox.Show("Calendar event has been deleted.");
nadinCodeHat
  • 83
  • 1
  • 7