Qui*_*nry 5 c# outlook calendar
我想创建一个程序,以便可以在其他人的Outlook日历中创建约会。例如:如果某人要求他的老板免费使用五天,则他们的老板需要能够批准它,并立即使其在该人的外表日历中可见。我已经编写了一些代码,可以在其中设置您自己的约会。这是我的代码:
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
AddAppointment("ConferenceRoom #2345", "We will discuss progression the group project.", "Group Project", new DateTime(2016, 02, 23, 15, 30, 52), new DateTime(2016, 02, 23, 20, 30, 52));
}
private void AddAppointment(string location, string body, string subject, DateTime startdatum, DateTime einddatum)
{
try
{
var AppOutlook = new Outlook.Application();
Outlook.AppointmentItem newAppointment =
(Outlook.AppointmentItem)
AppOutlook.CreateItem(Outlook.OlItemType.olAppointmentItem);
newAppointment.Start = startdatum;
newAppointment.End = einddatum;
newAppointment.Location = location;
newAppointment.Body = body;
newAppointment.BusyStatus=Outlook.OlBusyStatus.olTentative;
newAppointment.AllDayEvent = true;
newAppointment.Subject = subject;
newAppointment.Save();
newAppointment.Display(true);
}
catch (Exception ex)
{
MessageBox.Show("The following error occurred: " + ex.Message);
}
}
Run Code Online (Sandbox Code Playgroud)
PS:对不起,如果我的英语不好。
我使用了 EWS api ( https://msdn.microsoft.com/en-us/library/office/dd633710(v=exchg.80).aspx )
我使用的代码是:
try
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials("user@domain.com", "password");
service.Url = new Uri("https://mail.domain.com/EWS/Exchange.asmx");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "user2@domain.com");
Appointment appointment = new Appointment(service);
// Set the properties on the appointment object to create the appointment.
appointment.Subject = "Tennis lesson";
appointment.Body = "Focus on backhand this week.";
appointment.Start = DateTime.Now.AddDays(2);
appointment.End = appointment.Start.AddHours(1);
appointment.Location = "Tennis club";
appointment.ReminderDueBy = DateTime.Now;
// Save the appointment to your calendar.
appointment.Save(SendInvitationsMode.SendToNone);
// Verify that the appointment was created by using the appointment's item ID.
Item item = Item.Bind(service, appointment.Id, new PropertySet(ItemSchema.Subject));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)