Webdav c# code to retrive properties of an Exchange Store Email?

markm75

Newcomer
Joined
Jan 16, 2006
Messages
15
Hi there,

I have found code samples out there that are able to retrieve say the subjects of someone's inbox, using the Search method and a query in Webdav commands... But I really also need to be able to retrive body information and ideally, if there is an attachment present (I need to look for xml in an email's body if it exists). Does anyone know of the correct syntax/code for searching for things in the body and if possible attachments?

Here was the code I had found so far:
C#:
--------------
// Build the SQL query.
            strQuery = "<?xml version=\"1.0\"?><D:searchrequest xmlns:D = \"DAV:\" >"
                        + "<D:sql>SELECT \"DAV:displayname\" FROM \"" + strRootURI + "\""
                        + "WHERE \"DAV:ishidden\" = false AND \"DAV:isfolder\" = false"
                        + "</D:sql></D:searchrequest>";

            // Create a new CredentialCache object and fill it with the network
            // credentials required to access the server.
            MyCredentialCache = new System.Net.CredentialCache();
            MyCredentialCache.Add( new System.Uri(strRootURI),
               "NTLM",
               new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
               );

            // Create the HttpWebRequest object.
            Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);

            // Add the network credentials to the request.
            Request.Credentials = MyCredentialCache;

            // Specify the method.
            Request.Method = "SEARCH";

            // Encode the body using UTF-8.
            bytes = Encoding.UTF8.GetBytes((string)strQuery);

            // Set the content header length.  This must be
            // done before writing data to the request stream.
            Request.ContentLength = bytes.Length;

            // Get a reference to the request stream.
            RequestStream = Request.GetRequestStream();

            // Write the SQL query to the request stream.
            RequestStream.Write(bytes, 0, bytes.Length);

            // Close the Stream object to release the connection
            // for further use.
            RequestStream.Close();

            // Set the content type header.
            Request.ContentType = "text/xml";

            // Send the SEARCH method request and get the
            // response from the server.
            Response = (HttpWebResponse)Request.GetResponse();

            // Get the XML response stream.
            ResponseStream = Response.GetResponseStream();

            // Create the XmlDocument object from the XML response stream.
            ResponseXmlDoc = new XmlDocument();
            ResponseXmlDoc.Load(ResponseStream);

            // Build a list of the DAV:href XML nodes, corresponding to the folders
            // in the mailbox.  The DAV: namespace is typically assgigned the a:
            // prefix in the XML response body.
            DisplayNameNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname");

            if(DisplayNameNodes.Count > 0)
            {
               Console.WriteLine("Non-folder item display names...");

               // Loop through the display name nodes.
               for(int i=0; i<DisplayNameNodes.Count; i++)
               {
                  // Display the non-folder item displayname.
                  Console.WriteLine(DisplayNameNodes[i].InnerText);
               }
            }
            else
            {
               Console.WriteLine("No non-folder items found...");
            }
---------------

Thanks
 
Last edited by a moderator:
Back
Top