locked
WebDAV cannot support Exchange 2007 RRS feed

  • Question

  • User-380828621 posted

    Hi,

    I am trying to extract contact details from Outlook folder.

    When i tried to extract contacts from the public folder which is in Exchange 2007, I was not able to view the details.

    I tried to import them to my own folder which is based in Outlook 2003 I was able to view the details. Can someone advise me what is wrong?

     This is my code below.(the same code works on 2003 but not 2007).Thanks so much for any advise.

    public void PrintContactsUsingExchangeWebDAV()

    {

    string server = http://exchangeServer.com;

    NetworkCredential credentials = new NetworkCredential("username", "password", "exchange");

    string uri = string.Format("{0}/exchange/{1}", server, credentials.UserName);

    // Create a byte stream of the SQL query to run against the server

    // Link to Exchange store property names

    byte[] contents = Encoding.UTF8.GetBytes(string.Format(@"<?xml version=""1.0""?>

    <g:searchrequest xmlns:g=""DAV:"">

    <g:sql>

    SELECT

    *

    FROM

    Scope('SHALLOW TRAVERSAL OF ""{0}/exchange/{1}/Email Contact""')

    </g:sql>

    </g:searchrequest>"
    ,

    server, credentials.UserName));

    HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(uri);

    request.Credentials = credentials;

    request.Method =
    "SEARCH";

    request.ContentLength = contents.Length;

    request.ContentType = "text/xml";

    using (Stream requestStream = request.GetRequestStream())

    requestStream.Write(contents, 0, contents.Length);

    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)using (Stream responseStream = response.GetResponseStream())

    {

    // Process the response as an XML document

    XmlDocument document = new XmlDocument();

    document.Load(responseStream);

    int x = 0;foreach (XmlElement element in document.GetElementsByTagName("a:prop"))

    {

    if (x % 2 == 0)

    {

    // Do work with data returned for each contact

    ListBox1.Items.Add("FullName= " + (element["d:cn"] != null ? element["d:cn"].InnerText : "")

    + ",Surname= " + (element["d:sn"] != null ? element["d:sn"].InnerText : "")

    + ",Email= " + (element["d:email1"] != null ? element["d:email1"].InnerText : "")

    + ",Phone= " + (element["d:telephoneNumber"] != null ? element["d:telephoneNumber"].InnerText : "")

    + ",GivenName= " + (element["d:givenName"] != null ? element["d:givenName"].InnerText : "")

    + ",MiddleName= " + (element["d:middleName"] != null ? element["d:middleName"].InnerText : "")

    + ",MailAdd= " + (element["d:mailingaddressid"] != null ? element["d:mailingaddressid"].InnerText : "")

    + ",FileAs= " + (element["d:fileas"] != null ? element["d:fileas"].InnerText : "")

    + ",Fax= " + (element["d:faxNumber"] != null ? element["d:faxNumber"].InnerText : ""));}

    x++;

    }

    }

    }

    Friday, May 9, 2008 5:58 AM

All replies