我在视觉工作室工作,正在进行Outlook集成以添加新约会。
在软件内部,用户必须使用dateTime组件选择日期和时间(使用自定义格式显示时间)。
然后我将这些信息解析为下面的Outlook代码:
Microsoft.Office.Interop.Outlook.Application outlookApp =
new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.AppointmentItem Appointment =
(Microsoft.Office.Interop.Outlook.AppointmentItem)
outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
Appointment.Subject = "Appraisal With " + tbFirstName.Text + " " + tbSurname.Text;
Appointment.Body = "Appraisal with " + tbFirstName.Text + " " + tbSurname.Text +
"\n\n Details:\n-----------------------------------------\n First Name: " +
tbFirstName.Text + "\nSurname: " + tbSurname.Text + "\n Address: " + tbAddress.Text +
"\nDate & Time: " + dtpAppointment.ToString() + "\nContact Number: " +
tbPhoneNumber.Text + "\nEmail: " + tbEmail.Text;
Appointment.Location = tbAddress.Text;
Appointment.ReminderSet = true;
Appointment.ReminderMinutesBeforeStart = 120;
Appointment.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
Appointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
Appointment.Save();
这样可以很好地添加约会,但是我需要在约会中添加日期和时间字段,对于我的生活,我无法理解。
如果我使用这一行:
Appointment.Start = dtpAppointment.Value;
我们的日期还可以,但时间总是提交时计算机上的当前时间。我需要约会的日期和预约时间。
答案 0 :(得分:0)
DateTimePicker
的自定义格式是什么?如果未显示时间,则Value
将始终为所选日期和当前系统时间。
答案 1 :(得分:0)
我想出了这个。
我正在将String推入一个期望DateTime类型对象的字段。 默认情况下,这包括日期和时间,所以outlook在日期或时间部分中不知道放在哪里?
我只将时间转换为字符串。
for (j in 1:3)
现在分隔的日期和时间我只将时间传递回一个单独的DateTime对象。
string time = dtpAppointment.Value.ToString("HH:mm");
然后我指定了Appointment.Start()参数两次为日期,另一次为时间,并将它们自动放入它们所属的部分。
希望这有助于其他人:)