2015-04-02 71 views
0

我已经做了一些研究,并没有找到我的确切问题的例子,虽然有很多很抱歉,如果我错过了它。使用Outlook.AppointmentItem o预约特定用户

我有一些代码会自动添加约会到我的Outlook日历,然后发送电子邮件给收件人。但是现在我希望能够将其添加到通用用户名的公共日历中...所以我使用的代码仅将其添加到已登录的用户日历中。

继承此问题的代码在按下按钮:

private void button1_Click(object sender, EventArgs e) 
    { 
     string name = "Test Name"; 
     DateTime startDate = new DateTime(2015, 4, 2); 
     DateTime endDate = new DateTime(2015, 4, 2); 


     Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app 
     Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment 

     oAppointment.Subject = "Enquiry Changes made to " + name + "'s enquiry"; // set the subject 
     oAppointment.Body = "This is where the appointment body of the appointment is written"; // set the body 
     oAppointment.Location = "The location"; // set the location 
     oAppointment.Start = Convert.ToDateTime(startDate); // Set the start date 
     oAppointment.End = Convert.ToDateTime(endDate); // End date 
     oAppointment.ReminderSet = true; // Set the reminder 
     oAppointment.ReminderMinutesBeforeStart = 15; // reminder time 
     oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance 
     oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy; 

     oAppointment.Save(); 

     Outlook.MailItem mailItem = oAppointment.ForwardAsVcal(); 
     // email address to send to 
     mailItem.To = "[email protected]"; 

     // send 
     mailItem.Send(); 
    } 

感谢任何帮助,您可以给我....并澄清,我希望能够将约会添加到特定用户的日历,而不是为用户当前登录到机器上。

这里是极为相似的链接,但是也没有一个公认的回答:How to set an appointment to other users on outlook?

+0

恩,你链接到_does_的另一个问题有一个答案。 – RenniePet 2015-04-02 08:39:55

+0

它没有被接受,并提供的链接是没有用的......我尝试使用此: https://www.add-in-express。com/creation-addins-blog/2011/11/04/outlook-create-appointment-item/ 但它不起作用 – Crezzer7 2015-04-02 08:44:56

+0

我不明白。该主题的答案已被接受,并且Dmitry Streblechenko是与Outlook接口的头号专家。他是Outlook Spy的作者,这是一个用于调查Outlook使用的MAPI结构的伟大程序。 http://www.dimastr.com/outspy/home.htm – RenniePet 2015-04-02 08:59:07

回答

0

使用Outlook交易所API解决了我的问题:

//This will initialize the exchange web service object 
     ExchangeService exchangeService = new ExchangeService(ExchangeVersion.Exchange2013); 
     //Setting service URL 
     try 
     { 
      exchangeService.AutodiscoverUrl("[email protected]"); 
     } 
     catch (AutodiscoverLocalException ex) 
     { 
      //If auto discover URL fails mannualy configure the exchange service URL 
      exchangeService.Url = new Uri("https://yourexchangename/EWS/Exchange.asmx"); 
      Console.WriteLine(ex.Message); 
     } 
     exchangeService.Credentials = new WebCredentials("username", "password", "domain"); 
     //OR 
     exchangeService.Credentials = new NetworkCredential("username", "password", "domain"); 

     Appointment appointment = new Appointment(exchangeService); 
     appointment.Subject = "Sample subject"; 
     appointment.Body = "sample Body"; 
     appointment.Start = new DateTime(2015, 4, 1, 8, 0, 0); 
     appointment.End = appointment.Start.AddHours(9.5); 
     // Occurs every weeks on Tuesday and Thursday 
     appointment.Save(); 

这段代码将尝试3种方式连接到特定的用户帐户,在我的情况下,这是一个共享日历保存的通用用户。代码的第二部分将直接添加约会到您的日历....希望这可以帮助人们

0

我很高兴你发现我的文章有帮助。

要添加一个新的约会项目到公共(即chared)日历,您需要首先获取共享文件夹。为了完成工作,您需要使用Namespace类的GetSharedDefaultFolder方法,该方法返回一个Folder对象,该对象表示指定用户的指定默认文件夹。例如:

Sub ResolveName() 
    Dim myNamespace As Outlook.NameSpace 
    Dim myRecipient As Outlook.Recipient 
    Dim CalendarFolder As Outlook.Folder 
    Set myNamespace = Application.GetNamespace("MAPI") 
    Set myRecipient = myNamespace.CreateRecipient("Dan Wilson") 
    myRecipient.Resolve 
    If myRecipient.Resolved Then 
    Call ShowCalendar(myNamespace, myRecipient) 
    End If 
End Sub 

Sub ShowCalendar(myNamespace, myRecipient) 
    Dim CalendarFolder As Outlook.Folder 
    Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar) 
    CalendarFolder.Display 
End Sub 

而且你会发现whic打开通过URL或文件名中引用的共享文件夹的命名空间类的OpenSharedFolder方法。此方法用于访问下面的共享文件夹类型:

  • WebCal的日历(而webcal:// mysite的/ mycalendar)
  • RSS饲料(饲料:// mysite的/ myfeed)
  • 微软的SharePoint Foundation文件夹(stssync:// mysite的/ MyFolder文件)
  • 的iCalendar日历(.ICS)文件
  • vCard联系人(的.vcf)文件
  • Outlook邮件(的.msg)文件

然后,您可以使用Items属性使用方法添加新的约会项目。

作为考虑使用EWS的替代方法,请参阅EWS Managed API, EWS, and web services in Exchange以获取更多信息。