Skip to content

Instantly share code, notes, and snippets.

@mayuki
Created April 17, 2009 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayuki/96940 to your computer and use it in GitHub Desktop.
Save mayuki/96940 to your computer and use it in GitHub Desktop.
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