Created
April 17, 2009 09:18
-
-
Save mayuki/96940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Main(String[] args) | |
{ | |
var baseUrl = "http://exch2003/exchange/Alias/予定表"; | |
var xDoc = QueryToExchange(baseUrl, | |
String.Format( | |
@"SELECT | |
* | |
FROM | |
SCOPE('Shallow Traversal of """ + baseUrl + @"""') | |
WHERE | |
(""urn:schemas:calendar:dtstart"" >= CAST(""{0}"" as 'dateTime')) | |
AND | |
(""urn:schemas:calendar:dtstart"" <= CAST(""{1}"" as 'dateTime')) | |
", DateTime.Today.ToString("o"), DateTime.Today.AddDays(1).AddSeconds(-1).ToString("o"))); | |
XNamespace xNsE = "urn:schemas:httpmail:"; | |
XNamespace xNsD = "DAV:"; | |
XNamespace xNsC = "urn:schemas:calendar:"; | |
var ret = from e in xDoc.Elements().Elements(xNsD + "response").Elements(xNsD + "propstat") | |
where e.Element(xNsD + "status").Value == "HTTP/1.1 200 OK" | |
let prop = e.Element(xNsD + "prop") | |
let start = DateTime.Parse(prop.Element(xNsC + "dtstart").Value) | |
let end = DateTime.Parse(prop.Element(xNsC + "dtend").Value) | |
orderby start descending | |
select new | |
{ | |
Subject = prop.Element(xNsE + "subject").Value, | |
Location = prop.Element(xNsC + "location").Value, | |
Start = start, | |
End = end, | |
Propstat = e | |
}; | |
} | |
private static XDocument QueryToExchange(String url, String query) | |
{ | |
XDocument requestXDoc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), | |
new XElement("{DAV:}searchrequest", | |
new XElement("{DAV:}sql", query) | |
)); | |
// データをWebDAVで取得 | |
using (WebClient webClient = new WebClient()) | |
{ | |
webClient.Headers["Accept"] = "text/xml, application/xml"; | |
webClient.Headers["Content-Type"] = "text/xml"; | |
webClient.UseDefaultCredentials = true; | |
webClient.Encoding = Encoding.UTF8; | |
return XDocument.Parse(webClient.UploadString(url, "SEARCH", requestXDoc.ToString())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment