我有一段遗留代码可以从日历中获取所有约会。
private List<string> GetCalendarItemsByDay(string folderId)
{
var items = new List<string>();
using (var handler = new HttpClientHandler { Credentials = new NetworkCredential(_calenderSettings.Username, _calenderSettings.Password) })
using (var client = new HttpClient(handler) { Timeout = TimeSpan.FromMinutes(10) })
{
var soapRequest =
string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"">
<soap:Header>
<t:RequestServerVersion Version=""Exchange2010"" />
</soap:Header>
<soap:Body>
<FindItem xmlns=""http://schemas.microsoft.com/exchange/services/2006/messages"" xmlns:t=""http://schemas.microsoft.com/exchange/services/2006/types"" Traversal=""Shallow"">
<ItemShape>
<t:BaseShape>IdOnly</t:BaseShape>
</ItemShape>
<ParentFolderIds>
<t:FolderId Id=""{0}"" />
</ParentFolderIds>
</FindItem>
</soap:Body>
</soap:Envelope>", folderId);
try
{
var content = new StringContent(soapRequest, Encoding.UTF8, "text/xml");
var request = new HttpRequestMessage(HttpMethod.Post, _calenderSettings.EwsUri)
{
Content = content
};
var response = client.SendAsync(request).Result;
using (var responseStream = response.Content.ReadAsStreamAsync().Result)
{
var nav = new XPathDocument(responseStream).CreateNavigator();
var nsManager = new XmlNamespaceManager(nav.NameTable);
nsManager.AddNamespace("t", "http://schemas.microsoft.com/exchange/services/2006/types");
var folderNodes = nav.Select("//t:ItemId", nsManager);
foreach (XPathNavigator folderNode in folderNodes)
{
items.Add(folderNode.TryGetNodeValue<string>("@Id", nsManager));
}
}
}
catch (AggregateException a)
{
Log.For(this).Debug(a.Message);
}
}
return items;
}
这很好,但我只需要接下来10天的约会。 是否可以在soap请求中添加日期过滤器?
之后我尝试过滤掉它们,但响应中不包含日期。
答案 0 :(得分:1)
您需要在代码中使用CalendarView,您可以在其中指定StartDate和EndDate。例如
WillDisplay