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.

HOWTO: Use PROPPATCH in WebDAV to Change a Property Value of a Word Document


View products that this article applies to.

This article was previously published under Q289870

↑ Back to the top


Summary

This article demonstrates the use of the Web Distributed Authoring and Versioning (WebDAV) PROPRATCH command to change the value of a property on a Microsoft Word document in a public folder.

↑ Back to the top


More information

The following Visual C++ code sample uses the HTTPRequest object to send a PROPPATCH request to the Exchange server for the Author property of the Word document and get a response back stating if the value was changed.

This sample uses the following namespaces:
xmlns:a='DAV:'
xmlns:o='urn:schemas-microsoft-com:office:office'
This sample requires Msxml.dll version 2.0 or later.

To run this sample, follow these steps:
  1. Under Public folders, create a new folder and name it "Testfolder".
  2. In Testfolder, create a new Word document and name it "Test.doc".
  3. In Visual C++, create a new Win32 console application and name it "Mysample".
  4. Replace the code in the Mysample.cpp file with the following code:
    #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 below to reflect your server.
          bstr_t yourServerName = "myserver1";
    
          bstr_t sUrl = "http://" + yourServerName +
            "/public/testfolder/test.doc";
          bstr_t sMethod = "PROPPATCH";
             
    //TODO: Change the 2 lines below 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 + "<a:propertyupdate xmlns:a='DAV:' xmlns:o=" +
             "'urn:schemas-microsoft-com:office:office'>";
          sReq = sReq + "<a:set><a:prop>";
          sReq = sReq + "<o:Author>someone else</o:Author>";
          sReq = sReq + "</a:prop></a:set></a:propertyupdate>";
     
          // Send the request to set the search criteria.
          pXMLHttpReq->send(sReq);
    
          // OK, get 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.
  6. Compile and then run the code.
  7. At the end, you will see the Status as "200 OK". The StatusText will display the status as "HTTP/1.1 200 OK" if the value was changed.
  8. You can then use PROPFIND to look up this property and you will see that it has changed to "Someone Else".

↑ Back to the top


Keywords: KB289870, kbmsg, kbhowto

↑ Back to the top

Article Info
Article ID : 289870
Revision : 6
Created on : 2/22/2007
Published on : 2/22/2007
Exists online : False
Views : 562