PROPPATCH Sample Code

                 

 
Special Edition Using Microsoft SharePoint Portal Server
By Robert  Ferguson

Table of Contents
Chapter  16.   Using WebDAV Protocol to Create Web Parts


In this example, we will see how we can create and set the properties of a Word document using the PROPPATCH method.

The name of the document is promotoc4.doc, and it is located in the /DOCUMENT/MARKETING/ APRIL / folder.

We want to change the DAV:owner property and create new properties such as Author, Company, and Title. The last three properties are the properties of an MS Word document, so we should refer to the URN as xmlns:o='urn:schemas-microsoft-com:office:office' and use the o: prefix in front of these properties to identify them correctly.

The strURL variable needs to point to the resource as

 strURL = "http://" + strServer + "/" + strWorkspace + "/DOCUMENTS/MARKETING/APRIL/ graphics/ccc.gif promotoc4.doc" 

The XML string needs to be modified to

 strXMLRequest = "" + _  "<?xml version='1.0'?>" + _  "<D:propertyupdate xmlns:D='DAV:' xmlns:o='urn:schemas-microsoft-com:office:office'>" + _      "<D:set>" + _          "<D:prop>" + _              "<D:owner>Reza Dianat</D:owner>" + _              "<o:Author>Reza Dianat</o:Author>" + _              "<o:company>COMPAQ</o:company>" + _              "<o:title>Promotion</o:title>" + _          "</D:prop>" + _      "</D:set>" + _  "</D:propertyupdate>" 

We also need to identify the PROPPATCH method in the request header:

 DAVRequest.open "PROPPATCH", strURL, False, strUser, strPassword 
Listing 16.4 The PROPPATCH Request
 PROPPATCH /spsbook/documents/marketing/april/promotco4.doc HTTP/1.1 Host: dianatr Content-Type: text/xml Content-Length: XXX <?xml version='1.0'?>  <D:propertyupdate xmlns:D='DAV:' xmlns:o='urn:schemas-microsoft-com:office:office'>      <D:set>       <D:prop>              <D:owner>Reza Dianat</D:owner>              <o:Author>Reza Dianat</o:Author>              <o:company>COMPAQ</o:company>              <o:title>Promotion</o:title>          </D:prop>      </D:set>  </D:propertyupdate> 

Listing 16.5 shows the XML response that is saved in the proppatch.xml file. Status code 200 means all the properties were updated successfully.

Listing 16.5 The Web Server Response to the PROPPATCH Request
 <?xml version="1.0" ?> <a:multistatus xmlns:b="urn:schemas-microsoft-com:office:office" xmlns:a="DAV:"> <a:response> <a:href>http://dianatr/spsbook/Documents/Marketing/April/promotoc4.doc</a:href> <a:propstat> <a:status>HTTP/1.1 200 OK</a:status> <a:prop> <a:owner /> <b:Author /> <b:company /> <b:title /> </a:prop> </a:propstat> </a:response> </a:multistatus> 
Listing 16.6 The Complete VBScript Code for the PROPPTACH Method
 Dim strPassword Dim DAVRequest Dim strXMLRequest strServer = "dianatr" strWorkspace = "spsbook" strUser = "dianatr0\spsuser" strPassword = "spspw" strURL = "http://" + strServer + "/" + strWorkspace + "/DOCUMENTS/MARKETING/APRIL/ graphics/ccc.gif promotoc4.doc" strURL = Replace(strURL, " ", "%20") strXMLRequest = "" + _ "<?xml version='1.0'?>" + _ "<D:propertyupdate xmlns:D='DAV:' xmlns:o='urn:schemas-microsoft-com:office:office'>" + _      "<D:set>" + _       "<D:prop>" + _              "<D:owner>Reza Dianat</D:owner>" + _              "<o:Author>Reza Dianat</o:Author>" + _              "<o:company>COMPAQ</o:company>" + _              "<o:title>Promotion</o:title>" + _          "</D:prop>" + _      "</D:set>" + _ "</D:propertyupdate>" Set DAVRequest = CreateObject("MSXML2.xmlhttp") DAVRequest.open "PROPPATCH", strURL, False, strUser, strPassword DAVRequest.setRequestHeader "Content-Type", "text/xml" DAVRequest.send strXMLRequest Set xmlBody = CreateObject("MSXML2.domdocument") xmlBody.async = False xmlBody.load DAVRequest.responseXML xmlBody.save "proppatch.xml" 

                 
Top


Special Edition Using Microsoft SharePoint Portal Server
Special Edition Using Microsoft SharePoint Portal Server
ISBN: 0789725703
EAN: 2147483647
Year: 2002
Pages: 286

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net