Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to use the PROPFIND command in WebDAV to find a property value on a public folder item


View products that this article applies to.

Summary

This article describes the use of the Web Distributed Authoring and Versioning (WebDAV) PROPFIND command to locate the value of a property on an item in a public folder.

↑ Back to the top


More information

The following Microsoft Visual C++ code sample uses the HTTPRequest object to send a PROPFIND request to the Exchange server for the DisplayName property of the mail item. Then, the code obtains the value of the property in the response text of the request. This code sample requires Msxml.dll 2.0 or a later version of Msxml.dll.

To run this sample, follow these steps:
  1. Under Public folders, create a new folder, and then name the folder Testfolder.
  2. In the Testfolder folder, create a mail item that has the subject "test".
  3. In Visual C++, create a new Win 32 console application, and then name the application Mysample.
  4. Replace the code in the Mysample.cpp file with the following code sample.
    #include<stdio.h>
    
    //TODO: Change the path here if your Msxml.dll file is in a different location.
    
    // for xml 4.0
    #import "c:\winnt\system32\msxml4.dll"
    using namespace MSXML2;
    
    // for xml 2.0
    // #import "c:\winnt\system32\msxml2.dll"
    // using namespace MSXML;
    
    int main(int argc, char* argv[])
    {
       CoInitialize(NULL);
       try
       {
       //TODO: Change the line in the following code to reflect the server.
       bstr_t yourServerName = "myserver1";
    
       bstr_t sUrl = "http://" + yourServerName + 
          "/public/TestFolder/test.eml";
       bstr_t sMethod = "PROPFIND";
             
       //TODO: Change the two lines in the following code to reflect your user name and password.
       _variant_t vUser = L"myserver1\\User1";
       _variant_t vPassword = L"password";
          
       // for xml 4.0
          MSXML2::IXMLHTTPRequestPtr pXMLHttpReq=NULL; 
          // for xml 2.0
          MSXML::IXMLHTTPRequestPtr pXMLHttpReq=NULL; 
    
          HRESULT hr = ::CoCreateInstance(
    			CLSID_XMLHTTPRequest,
                            NULL, 
                            CLSCTX_INPROC_SERVER, 
    			IID_IXMLHttpRequest,
                           (LPVOID*)&pXMLHttpReq);
    
       if (S_OK != hr)
       {
          printf("XML Http Request pointer creation failed\n");
          return 0;
       }
    
       // Call open function.
    
       _variant_t vAsync = (bool)FALSE;
       pXMLHttpReq->open(sMethod, 
             sUrl, 
             vAsync, 
             vUser, 
             vPassword);
    
       pXMLHttpReq->setRequestHeader((bstr_t)"Content-Type", 
          (bstr_t)"text/xml");
       bstr_t sReq;
       sReq =  "<?xml version='1.0'?>";
       sReq = sReq +  "<d:propfind xmlns:d='DAV:'><d:prop>" +
          "<d:displayname/>" + //TODO: Change to the property that you want.
          "</d:prop></d:propfind>";
    
       // Send the request to set the search criteria.
       pXMLHttpReq->send(sReq);
    
       // Obtain a response.      
       long lStatus;
       pXMLHttpReq->get_status(&lStatus);
    
       printf("\n~~~~~~~~\n%d\n", lStatus);
       BSTR bstrResp;
       pXMLHttpReq->get_statusText(&bstrResp);
       printf("\n~~~~~~~~\n%s\n", (char*)(bstr_t)bstrResp);
    
       _bstr_t bstrAllHeaders;
       bstrAllHeaders = pXMLHttpReq->getAllResponseHeaders();
       printf("\n~~~~~~~~\n%s\n", (char*)bstrAllHeaders);
    
       BSTR bstrResponseText;
       pXMLHttpReq->get_responseText(&bstrResponseText);
       printf("\n~~~~~~~~\n%s\n", (char*)(bstr_t)bstrResponseText);   
       }
       catch(_com_error &e)
       {
       printf("Error\a\a\n\tCode = %08lx\n"
          "\tCode meaning = %s\tSource = %s\n\tDescription = %s\n",
          e.Error(), 
          e.ErrorMessage(), 
          (char*)e.Source(), 
          (char*)e.Description() );
       }
    
       CoUninitialize(); 
       
       return 0;
    }
    					
  5. Make the changes marked by "TODO:" in the code sample.
  6. Compile and then run the code sample.

    After the code sample runs, you will see the Status, Status Test as "HTTP/1.1 200 OK" and the ResponseText property of your HTTPRequest. The ResponseText will have the DisplayName value that you are requesting.

Potential issues

Reading properties by using a PROPFIND command or by using ActiveX Data Objects (ADO) code in an event sink may not return all properties on some computers when the properties to read are not explicitly specified. When properties are not explicitly specified, the schema is used to obtain a list of properties to return. If there are problems with the schema, the PROPFIND command may not return all the properties that you expect. Sometimes, this issue has been reported after you upgrade from Exchange 2000 Server to Exchange Server 2003.

To avoid experiencing this issue, use one of the following methods:
  • Specify the exact properties in the XML request. This method should work even if the schema is corrupted.
  • Use Exchange Explorer from the Exchange Software Development Kit (SDK) to view properties for the item. If the same properties are not returned, the schema is probably the cause of the issue. Exchange Explorer uses the "PROPFIND allprops" command to retrieve properties.
  • Specify all the namespaces of the items that are needed in the XML of a PROPFIND command by using the allprops parameter.
If you believe that your schema is corrupted, you may want to contact Microsoft Product Support Services.

↑ Back to the top


Keywords: KB289867, kbmsg, kbhowto

↑ Back to the top

Article Info
Article ID : 289867
Revision : 7
Created on : 10/25/2007
Published on : 10/25/2007
Exists online : False
Views : 405