如何使用Exchange Web Service Managed API获取公共文件夹日历(包括循环会议)
在Exchange2010及其以后,MS提供了Managed API来调用Exchange的接口
下面代码演示了如何获取公共日历
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); service.Credentials = new NetworkCredential("user", "password", "domain"); service.Url = new Uri(https://wwww.sohu.com/ews/exchange.asmx); System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate( Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors ) { return true; }; //CAL string _id = "AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwBZaXl0Ei75TYF0WbP9Pt4/AAAFNPQsAAA="; CalendarView view = new CalendarView(DateTime.Now.AddDays(-5), DateTime.Now.AddDays(5)); CalendarFolder cf = CalendarFolder.Bind(service, new FolderId(_id)); //CalendarFolder.(service); //Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox); // service.ClientRequestId = _id; FindItemsResults<Appointment> findResults = cf.FindAppointments(view); foreach (Appointment appointment in findResults.Items) { Response.Write(appointment.Start+"--" + appointment.Subject + "<br>"); }
在上面代码里,有一个_id参数,他是日历的ID,下面代码演示了如何获取日历的ID
系统的入口是PublicFoldersRoot参数
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); service.Credentials = new NetworkCredential("user", "password", "domain"); service.Url = new Uri("https://www.sohu.com/ews/exchange.asmx"); System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate( Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors ) { return true; }; FolderView view = new FolderView(5); view.PropertySet = new PropertySet(BasePropertySet.IdOnly); view.PropertySet.Add(FolderSchema.DisplayName); view.Traversal = FolderTraversal.Shallow; FindFoldersResults findFolderResults = service.FindFolders(WellKnownFolderName.PublicFoldersRoot, view); //find specific folder foreach (Folder f in findFolderResults) { //show folderId of the folder "test" // if (f.DisplayName == "Test") Response.Write(f.DisplayName+"**"+f.Id.UniqueId+"<br>"); }