Microsoft KB Archive/289867

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

Article ID: 289867

Article Last Modified on 10/25/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft XML Core Services 4.0
 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Parser 3.0
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++, 32-bit Learning Edition 6.0
 * Microsoft Exchange Server 2003 Enterprise Edition
 * Microsoft Exchange Server 2003 Standard Edition

-



This article was previously published under Q289867



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.



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:  Under Public folders, create a new folder, and then name the folder Testfolder. In the Testfolder folder, create a mail item that has the subject &quot;test&quot;. In Visual C++, create a new Win 32 console application, and then name the application Mysample.  Replace the code in the Mysample.cpp file with the following code sample.
 * 1) include

//TODO: Change the path here if your Msxml.dll file is in a different location.

// for xml 4.0 using namespace MSXML2;
 * 1) import &quot;c:\winnt\system32\msxml4.dll&quot;

// for xml 2.0 // #import &quot;c:\winnt\system32\msxml2.dll&quot; // 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 = &quot;myserver1&quot;;

bstr_t sUrl = &quot;http://&quot; + yourServerName + &quot;/public/TestFolder/test.eml&quot;; bstr_t sMethod = &quot;PROPFIND&quot;; //TODO: Change the two lines in the following code to reflect your user name and password. _variant_t vUser = L&quot;myserver1\\User1&quot;; _variant_t vPassword = L&quot;password&quot;; // 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(&quot;XML Http Request pointer creation failed\n&quot;); return 0; }

// Call open function.

_variant_t vAsync = (bool)FALSE; pXMLHttpReq->open(sMethod,         sUrl,          vAsync,          vUser,          vPassword);

pXMLHttpReq->setRequestHeader((bstr_t)&quot;Content-Type&quot;,      (bstr_t)&quot;text/xml&quot;); bstr_t sReq; sReq = &quot;&quot;; sReq = sReq + &quot;&quot; + &quot;&quot; + //TODO: Change to the property that you want. &quot;</d:prop></d:propfind>&quot;;

// Send the request to set the search criteria. pXMLHttpReq->send(sReq);

// Obtain a response. long lStatus; pXMLHttpReq->get_status(&lStatus);

printf(&quot;\n\n%d\n&quot;, lStatus); BSTR bstrResp; pXMLHttpReq->get_statusText(&bstrResp); printf(&quot;\n\n%s\n&quot;, (char*)(bstr_t)bstrResp);

_bstr_t bstrAllHeaders; bstrAllHeaders = pXMLHttpReq->getAllResponseHeaders; printf(&quot;\n\n%s\n&quot;, (char*)bstrAllHeaders);

BSTR bstrResponseText; pXMLHttpReq->get_responseText(&bstrResponseText); printf(&quot;\n\n%s\n&quot;, (char*)(bstr_t)bstrResponseText); }  catch(_com_error &e) {  printf(&quot;Error\a\a\n\tCode = %08lx\n&quot;      &quot;\tCode meaning = %s\tSource = %s\n\tDescription = %s\n&quot;,      e.Error,       e.ErrorMessage,       (char*)e.Source,       (char*)e.Description ); }

CoUninitialize; return 0; }                   </li> Make the changes marked by &quot;TODO:&quot; in the code sample.</li> Compile and then run the code sample.

After the code sample runs, you will see the Status, Status Test as &quot;HTTP/1.1 200 OK&quot; and the ResponseText property of your HTTPRequest. The ResponseText will have the DisplayName value that you are requesting.</li></ol>

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 &quot;PROPFIND allprops&quot; 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.

Keywords: kbhowto kbmsg KB289867

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.