<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: DotNet code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 30 Aug 2008 09:01:35 GMT</pubDate>
    <description>DZone Snippets: DotNet code</description>
    <item>
      <title>&#232;&#381;&#183;&#229;?&#8211;Exchange&#230;&#339;&#170;&#232;&#175;&#187;&#233;&#8218;&#174;&#228;&#187;&#182;&#230;&#8226;&#176;</title>
      <link>http://snippets.dzone.com/posts/show/2820</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;private int GetUnReadMailCount()&lt;br /&gt;{&lt;br /&gt;string url=&#226;&#8364;&#339;http://mail.felixwoo.com/exchange/&#226;&#8364;?; //&#230;&#338;&#8225;&#229;&#174;&#353;Exchange&#230;&#339;?&#229;&#352;&#161;&#229;&#8482;&#168;&#229;&#339;&#176;&#229;?&#8364; &lt;br /&gt;System.Net.HttpWebRequest Request;&lt;br /&gt;System.Net.WebResponse Response;&lt;br /&gt;System.Net.CredentialCache MyCredentialCache;&lt;br /&gt;string strUserName = &#226;&#8364;&#339;wuf&#226;&#8364;?; //&#230;&#338;&#8225;&#229;&#174;&#353;&#231;&#8482;&#187;&#229;&#189;&#8226;&#231;&#353;&#8222;&#231;&#8221;&#168;&#230;&#710;&#183;&#229;??&lt;br /&gt;string strRootURI = url+strUserName ; //&#229;&#190;&#8212;&#229;&#710;&#176;&#232;&#166;?&#232;&#174;&#191;&#233;&#8212;&#174;&#233;&#8218;&#174;&#231;&#174;&#177;&#231;&#353;&#8222;WebDAV&#229;&#339;&#176;&#229;?&#8364;&lt;br /&gt;string strPassword = &#226;&#8364;&#339;123456&#226;&#8364;?; //&#230;&#338;&#8225;&#229;&#174;&#353;&#232;&#175;&#165;&#231;&#8221;&#168;&#230;&#710;&#183;&#231;&#353;&#8222;&#229;&#175;&#8224;&#231;&#160;?&lt;br /&gt;string strDomain = &#226;&#8364;&#339;felixwoo.com&#226;&#8364;?; //&#230;&#338;&#8225;&#229;&#174;&#353;&#229;&#376;&#376;&#229;??&lt;br /&gt;string strQuery ="";&lt;br /&gt;byte[] bytes = null;&lt;br /&gt;System.IO.Stream RequestStream = null;&lt;br /&gt;System.IO.Stream ResponseStream = null;&lt;br /&gt;XmlDocument ResponseXmlDoc = null;&lt;br /&gt;XmlNodeList HrefNodes= null;&lt;br /&gt;XmlNodeList SizeNodes= null;&lt;br /&gt;int count=0;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;  // &#231;&#8221;&#168;SQL&#230;&#376;&#165;&#232;&#175;&#162;WebDAV&#232;&#191;&#8221;&#229;&#8250;&#382;&#231;&#187;&#8220;&#230;&#382;&#339;&#228;&#184;&#173;&#231;&#353;&#8222;unreadcount&#232;&#352;&#8218;&#231;&#8218;&#185;.&lt;br /&gt;  strQuery = "&lt;?xml version=\"1.0\"?&gt;&lt;D:searchrequest xmlns:D = \"DAV:\" &gt;"&lt;br /&gt;   + "&lt;D:sql&gt;SELECT \"DAV:displayname\",\"urn:schemas:httpmail:unreadcount\" FROM \"" + strRootURI + "\""&lt;br /&gt;   + "&lt;/D:sql&gt;&lt;/D:searchrequest&gt;";&lt;br /&gt;&lt;br /&gt;  // &#229;&#710;&#8250;&#229;&#187;&#186;&#230;&#8211;&#176;&#231;&#353;&#8222;CredentialCache&#229;&#175;&#185;&#232;&#177;&#161;&#239;&#188;&#338;&#230;&#382;&#8222;&#229;&#187;&#186;&#232;&#186;&#171;&#228;&#187;&#189;&#229;&#8225;&#173;&#230;?&#174;&lt;br /&gt;  MyCredentialCache = new System.Net.CredentialCache();&lt;br /&gt;  MyCredentialCache.Add( new System.Uri(strRootURI),&lt;br /&gt;   "NTLM",&lt;br /&gt;   new System.Net.NetworkCredential(strUserName, strPassword, strDomain)&lt;br /&gt;   );&lt;br /&gt;&lt;br /&gt;  // Create the HttpWebRequest object.&lt;br /&gt;  Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);&lt;br /&gt;&lt;br /&gt;  // &#230;&#338;&#8225;&#229;&#174;&#353;HttpWebRequest&#231;&#353;&#8222;&#232;&#186;&#171;&#228;&#187;&#189;&#229;&#8225;&#173;&#230;?&#174;&#239;&#188;&#338;&#230;&#173;&#164;&#229;&#164;&#8222;&#228;&#184;&#186;&#229;&#8230;&#179;&#233;&#8221;&#174;&#230;&#8240;&#8364;&#229;&#339;&#168;&#227;&#8364;&#8218;&#229;&#166;&#8218;&#230;&#382;&#339;&#228;&#189;&#191;&#231;&#8221;&#168;&#228;&#185;&#8249;&#229;&#8240;?&lt;br /&gt;  // &#229;&#710;&#8250;&#229;&#187;&#186;&#231;&#353;&#8222;MyCredentialCache&#239;&#188;&#338;&#229;&#710;&#8482;&#232;&#191;&#8482;&#228;&#184;&#170;&#232;&#186;&#171;&#228;&#187;&#189;&#229;&#8225;&#173;&#230;?&#174;&#230;&#732;&#175;&#229;?&#175;&#228;&#187;&#165;&#228;&#187;&#381;Web&#230;&#339;?&#229;&#352;&#161;&#229;&#8482;&#168;&#228;&#188;&#160;&#233;&#8364;&#8217;&lt;br /&gt;  // &#229;&#710;&#176;Exchange&#230;&#339;?&#229;&#352;&#161;&#229;&#8482;&#168;&#231;&#353;&#8222;&#239;&#188;&#338;&#228;&#189;&#8224;&#230;&#732;&#175;&#232;&#191;&#8482;&#230;&#160;&#183;&#229;&#184;&#166;&#230;?&#165;&#231;&#353;&#8222;&#233;&#8212;&#174;&#233;&#162;&#732;&#228;&#185;&#376;&#229;&#190;&#710;&#230;&#732;&#381;&#230;&#732;&#190;&#239;&#188;&#338;&#229;&#176;&#177;&#230;&#732;&#175;&#228;&#184;?&#232;&#402;&#189;&#229;&#164;&#376;&#232;&#8225;&#170;&lt;br /&gt;  // &#229;&#352;&#168;&#232;&#381;&#183;&#229;?&#8211;&#229;&#189;&#8220;&#229;&#8240;?&#231;&#8482;&#187;&#229;&#189;&#8226;&#229;&#710;&#176;&#229;&#376;&#376;&#231;&#353;&#8222;&#231;&#8221;&#168;&#230;&#710;&#183;&#231;&#353;&#8222;&#232;&#186;&#171;&#228;&#187;&#189;&#227;&#8364;&#8218;&#229;?&#179;&#228;&#190;&#191;&#229;&#183;&#178;&#231;&#187;?&#230;&#710;?&#229;&#352;&#376;&#231;&#8482;&#187;&#229;&#189;&#8226;&#229;&#710;&#176;&#229;&#376;&#376;&#239;&#188;&#338;&#233;&#8218;&#163;&#228;&#185;&#376;&#229;?&#170;&lt;br /&gt;  // &#232;&#402;&#189;&#233;&#8364;&#353;&#232;&#191;&#8225;form&#229;&#8224;?&#230;&#172;&#161;&#232;&#190;&#8220;&#229;&#8230;&#165;&#231;&#8221;&#168;&#230;&#710;&#183;&#229;??&#229;&#175;&#8224;&#231;&#160;?&#227;&#8364;&#8218;&#229;&#8250;&#160;&#230;&#173;&#164;&#239;&#188;&#338;&#230;&#710;&#8216;&#229;&#339;&#168;&#232;&#191;&#8482;&#233;&#8225;&#338;&#231;&#8221;&#168;&#231;&#353;&#8222;&#230;&#732;&#175;&lt;br /&gt;  // Request.Credentials = CredentialCache.DefaultCredentials&#239;&#188;&#338;&lt;br /&gt;  // &#232;&#191;&#8482;&#230;&#160;&#183;&#228;&#190;&#191;&#229;?&#175;&#228;&#187;&#165;&#232;&#381;&#183;&#229;&#190;&#8212;&#229;&#189;&#8220;&#229;&#8240;?&#231;&#8221;&#168;&#230;&#710;&#183;&#231;&#353;&#8222;&#229;&#8225;&#173;&#230;?&#174;&#239;&#188;&#338;&#228;&#189;&#8224;&#230;&#732;&#175;&#232;&#191;&#8482;&#230;&#160;&#183;&#229;&#184;&#166;&#230;?&#165;&#231;&#353;&#8222;&#233;&#8212;&#174;&#233;&#162;&#732;&#228;&#190;&#191;&#230;&#732;&#175;&#228;&#184;&#352;&#233;?&#162;&#230;??&#229;&#710;&#176;&#231;&#353;&#8222;&lt;br /&gt;  // &#232;&#186;&#171;&#228;&#187;&#189;&#229;&#8225;&#173;&#230;?&#174;&#230;&#8212;&#160;&#230;&#179;&#8226;&#228;&#188;&#160;&#233;&#8364;&#8217;&#231;&#353;&#8222;&#233;&#8212;&#174;&#233;&#162;&#732;&#239;&#188;&#338;&#232;&#167;&#163;&#229;&#8224;&#179;&#230;&#8211;&#185;&#230;&#179;&#8226;&#232;&#175;&#183;&#229;&#8230;&#179;&#230;&#179;&#168;&#228;&#184;&#8249;&#231;&#175;&#8225;&#230;&#8211;&#8225;&#231;&#171;&#160;&#227;&#8364;&#8218;&lt;br /&gt;  Request.Credentials = MyCredentialCache;&lt;br /&gt;&lt;br /&gt;  // &#230;&#338;&#8225;&#229;&#174;&#353;WebDAV&#231;&#353;&#8222;SEARCH&#230;&#8211;&#185;&#230;&#179;&#8226;&lt;br /&gt;  Request.Method = "SEARCH";&lt;br /&gt;&lt;br /&gt;  // Encode the body using UTF-8.&lt;br /&gt;  bytes = Encoding.UTF8.GetBytes((string)strQuery);&lt;br /&gt;&lt;br /&gt;  // Set the content header length. This must be&lt;br /&gt;  // done before writing data to the request stream.&lt;br /&gt;  Request.ContentLength = bytes.Length;&lt;br /&gt;&lt;br /&gt;  // Get a reference to the request stream.&lt;br /&gt;  RequestStream = Request.GetRequestStream();&lt;br /&gt;&lt;br /&gt;  // Write the SQL query to the request stream.&lt;br /&gt;  RequestStream.Write(bytes, 0, bytes.Length);&lt;br /&gt;&lt;br /&gt;  // Close the Stream object to release the connection&lt;br /&gt;  // for further use.&lt;br /&gt;  RequestStream.Close();&lt;br /&gt;&lt;br /&gt;  // Set the content type header.&lt;br /&gt;  Request.ContentType = "text/xml";&lt;br /&gt;&lt;br /&gt;  // Send the SEARCH method request and get the&lt;br /&gt;  // response from the server.&lt;br /&gt;  Response = (HttpWebResponse)Request.GetResponse();&lt;br /&gt;&lt;br /&gt;  // Get the XML response stream.&lt;br /&gt;  ResponseStream = Response.GetResponseStream();&lt;br /&gt;&lt;br /&gt;  // &#229;&#710;&#8250;&#229;&#187;&#186;XmlDocument&#229;&#175;&#185;&#232;&#177;&#161;&#239;&#188;&#338;&#229;&#185;&#182;&#232;&#381;&#183;&#229;?&#8211;&#230;&#8221;&#182;&#228;&#187;&#182;&#231;&#174;&#177;&#231;&#353;&#8222;unreadcount&#232;&#352;&#8218;&#231;&#8218;&#185;&#231;&#353;&#8222;&#229;&#8364;&#188;&lt;br /&gt;  ResponseXmlDoc = new XmlDocument();&lt;br /&gt;  ResponseXmlDoc.Load(ResponseStream);&lt;br /&gt;  HrefNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname");&lt;br /&gt;  SizeNodes = ResponseXmlDoc.GetElementsByTagName("d:unreadcount");&lt;br /&gt;  for(int i=0;i&lt;HrefNodes.Count;i++)&lt;br /&gt;  {&lt;br /&gt;   if(HrefNodes[i].InnerText=="&#230;&#8221;&#182;&#228;&#187;&#182;&#231;&#174;&#177;")&lt;br /&gt;    count=int.Parse(SizeNodes[i].InnerText);&lt;br /&gt;  }&lt;br /&gt;  ResponseStream.Close();&lt;br /&gt;  Response.Close();&lt;br /&gt;}&lt;br /&gt;catch(Exception)&lt;br /&gt;{&lt;br /&gt;  // Catch any exceptions. Any error codes from the SEARCH&lt;br /&gt;  // method request on the server will be caught here, also.&lt;br /&gt;  return -1;&lt;br /&gt;}&lt;br /&gt;return count;&lt;br /&gt;} &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 15 Oct 2006 07:10:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2820</guid>
      <author>mornlee (mornlee)</author>
    </item>
  </channel>
</rss>
