我们在 Exchange 2007 公用文件夹中设置了我们公司的公用日历。我可以使用下面的代码检索我当天的个人日历约会。我在网上搜索了高低,但我找不到有人从公共文件夹日历中检索日历信息的示例。
似乎它应该是可行的,但我不能为我的生活让它工作。如何修改以下代码以访问日历?我对通过 asp.net 创建任何约会不感兴趣,只是检索一个简单的列表。我也愿意接受任何其他建议。谢谢。
额外的赏金
- 我不可能是唯一需要这样做的人。让我们为后代解决这个问题。
由于无知而再次更新
- 我没有提到我正在从事的项目是 .NET 2.0(你不觉得很重要吗?)。
* 在下面添加了我的代码解决方案 *
- 我已经用最终工作的代码替换了我的原始代码示例。非常感谢 Oleg 提供了查找公用文件夹的代码,这是最难的部分。我使用此处的示例修改了代码http://msexchangeteam.com/archive/2009/04/21/451126.aspx使用更简单的 FindAppointments 方法。
这个简单的示例返回一个包含约会的 html 字符串,但您可以将其用作基础来根据需要进行自定义。你可以在下面他的回答下看到我们的来回。
using System;
using Microsoft.Exchange.WebServices.Data;
using System.Net;
namespace ExchangePublicFolders
{
public class Program
{
public static FolderId FindPublicFolder(ExchangeService myService, FolderId baseFolderId,
string folderName)
{
FolderView folderView = new FolderView(10, 0);
folderView.OffsetBasePoint = OffsetBasePoint.Beginning;
folderView.PropertySet = new PropertySet(FolderSchema.DisplayName, FolderSchema.Id);
FindFoldersResults folderResults;
do
{
folderResults = myService.FindFolders(baseFolderId, folderView);
foreach (Folder folder in folderResults)
if (String.Compare(folder.DisplayName, folderName, StringComparison.OrdinalIgnoreCase) == 0)
return folder.Id;
if (folderResults.NextPageOffset.HasValue)
folderView.Offset = folderResults.NextPageOffset.Value;
}
while (folderResults.MoreAvailable);
return null;
}
public static string MyTest()
{
ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
myService.Credentials = new NetworkCredential("USERNAME", "PASSWORD", "DOMAIN");
myService.Url = new Uri("https://MAILSERVER/ews/exchange.asmx");
Folder myPublicFoldersRoot = Folder.Bind(myService, WellKnownFolderName.PublicFoldersRoot);
string myPublicFolderPath = @"PUBLIC_FOLDER_CALENDAR_NAME";
string[] folderPath = myPublicFolderPath.Split('\\');
FolderId fId = myPublicFoldersRoot.Id;
foreach (string subFolderName in folderPath)
{
fId = Program.FindPublicFolder(myService, fId, subFolderName);
if (fId == null)
{
return string.Format("ERROR: Can't find public folder {0}", myPublicFolderPath);
}
}
Folder folderFound = Folder.Bind(myService, fId);
if (String.Compare(folderFound.FolderClass, "IPF.Appointment", StringComparison.Ordinal) != 0)
{
return string.Format("ERROR: Public folder {0} is not a Calendar", myPublicFolderPath);
}
CalendarFolder AK_Calendar = CalendarFolder.Bind(myService, fId, BasePropertySet.FirstClassProperties);
FindItemsResults<Appointment> AK_appointments = AK_Calendar.FindAppointments(new CalendarView(DateTime.Now,DateTime.Now.AddDays(1)));
string rString = string.Empty;
foreach (Appointment AK_appoint in AK_appointments)
{
rString += string.Format("Subject: {0}<br />Date: {1}<br /><br />", AK_appoint.Subject, AK_appoint.Start);
}
return rString;
}
}
}