示例#1
0
        private void AddAppointment(string subject, string body, DateTime startdatum, DateTime sluttatum)
        {
            try
            {
                Microsoft.Office.Interop.Outlook.AppointmentItem newAppointment =
                    (Microsoft.Office.Interop.Outlook.AppointmentItem)
                    _application.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
                newAppointment.Start       = startdatum;
                newAppointment.End         = sluttatum;
                newAppointment.AllDayEvent = false;
                newAppointment.BusyStatus  = Microsoft.Office.Interop.Outlook.OlBusyStatus.olTentative;
                newAppointment.Location    = "Platsangivelse...";

                // Bifoga ett dokument om så önskas
                OpenFileDialog attachment = new OpenFileDialog();
                attachment.Title = appointheader.Text;
                attachment.ShowDialog();
                if (attachment.FileName.Length > 0)
                {
                    newAppointment.Attachments.Add(attachment.FileName,
                                                   Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,
                                                   1,
                                                   attachment.FileName);
                }

                Microsoft.Office.Interop.Outlook.Recipients sentTo     = newAppointment.Recipients;
                Microsoft.Office.Interop.Outlook.Recipient  sentInvite = null;
                sentInvite      = sentTo.Add("Holly Holt");
                sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType
                                  .olRequired;
                sentInvite      = sentTo.Add("David Junca ");
                sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType
                                  .olOptional;
                sentTo.ResolveAll();

                newAppointment.Subject = subject;
                newAppointment.Body    = body;
                newAppointment.Save();
                // newAppointment.Display(true);
                newAppointment.Close(OlInspectorClose.olSave); // Detta gör att man inte behöver stänga dialogen manuellt
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("The following error occurred: " + ex.Message);
            }
        }