在Exchange2010及其以后,MS提供了来调用Exchange的接口
下面代码演示了如何获取公共日历
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010); service.Credentials = new NetworkCredential("user", "password", "domain"); service.Url = new Uri(); 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; FindItemsResultsfindResults = cf.FindAppointments(view); foreach (Appointment appointment in findResults.Items) { Response.Write(appointment.Start+"--" + appointment.Subject + " "); }
系统的入口是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+""); }