Microsoft KB Archive/300185

= How To Get and Set a Property on a Public Folder Item Using WebDAV =

Article ID: 300185

Article Last Modified on 5/9/2007

-

APPLIES TO


 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft XML Parser 2.0
 * Microsoft XML Parser 2.5
 * Microsoft XML Parser 2.6
 * Microsoft XML Core Services 4.0
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q300185



SUMMARY
In Exchange 2000 you can get and set properties by using Web Distributed Authoring and Versioning (WebDAV). This article provides a Visual Basic example of how to use the WebDAV PROPFIND and PROPPATCH commands to get and set a property on a public folder item.



MORE INFORMATION
To get and set the subject of an item in a public folder, follow these steps:  In Exchange 2000 Server, under All Public Folders, create a public folder and name it Folder1. In Folder1, create an item and name it Test1. In Visual Basic, create a Standard EXE project. Form1 is created by default. Add a command button to Form1 and name it Command1. Add a reference to the Microsoft XML Object Library.  Paste the following code in the code section of Form1:NOTE: Change e2kServer in the code to the name of your Exchange server. Also, change the UserID and password that are mentioned in the &quot;TO DO&quot; comments to correspond to the appropriate user. Private Sub Command1_Click sSourceURL = &quot;http://e2kServer/public/Folder1/Test1.eml&quot;

sUserID = &quot;Domain\UserID&quot; 'TO DO Change the UserID. sPassword = &quot;Password&quot; 'TO DO Change the Password. sSubject = PropFind(sSourceURL, sUserID, sPassword) MsgBox sSubject

'To change the subject, uncomment the following line. 'PropPatch sSourceURL, &quot;NewSubject&quot; End Sub

Function PropFind(ByVal sSourceURL As String, ByVal sUserID As String, ByVal sPassword As String) As String

Dim sReq As String

'TO use MSXML 2.0 use the following DIM/SET statements Dim XMLreq As XMLHTTP Set XMLreq = CreateObject(&quot;Microsoft.xmlhttp&quot;) Set oDocBack = CreateObject(&quot;MICROSOFT.XMLDOM&quot;)

'To use MSXML 4.0 use the folloiwing DIM/SET statements 'Dim XMLreq As MSXML2.XMLHTTP40 'Set XMLreq = CreateObject(&quot;Msxml2.XMLHTTP.4.0&quot;) 'Set oDocBack = CreateObject(&quot;MSXML2.DomDocument.4.0&quot;)

XMLreq.open &quot;PROPFIND&quot;, sSourceURL, False, sUserID, sPassword

'Set the header. XMLreq.setRequestHeader &quot;Content-Type&quot;, &quot;text/xml&quot; sReq = &quot;&quot; sReq = sReq & &quot;&quot; sReq = sReq & &quot;<m:subject/>&quot; sReq = sReq & &quot;</d:prop></d:propfind>&quot;

XMLreq.send sReq

Set oDocBack = XMLreq.responseXML Set objNodeList = oDocBack.getElementsByTagName(&quot;d:subject&quot;) PropFind = objNodeList(0).Text

End Function

Sub PropPatch(ByVal sSourceURL As String, ByVal sNewVal As String)

Dim sReq As String

'TO use MSXML 2.0 use the following DIM/SET statements Dim XMLreq As XMLHTTP Set XMLreq = CreateObject(&quot;Microsoft.xmlhttp&quot;)

'To use MSXML 4.0 use the folloiwing SET/DIM statements 'Dim XMLreq As MSXML2.XMLHTTP40 'Set XMLreq = CreateObject(&quot;Msxml2.XMLHTTP.4.0&quot;)

XMLreq.open &quot;PROPPATCH&quot;, sSourceURL, False, sUserID, sPassword

'Set the header. XMLreq.setRequestHeader &quot;Content-Type&quot;, &quot;text/xml&quot;

sReq = &quot;<?xml version='1.0'?>&quot; sReq = sReq & &quot;<d:propertyupdate xmlns:d='DAV:' xmlns:m='urn:schemas:mailheader:'>&quot; sReq = sReq & &quot;<d:set><d:prop>&quot; sReq = sReq & &quot;<m:subject>&quot; & sNewVal & &quot;</m:subject>&quot; sReq = sReq & &quot;</d:prop></d:set></d:propertyupdate>&quot; XMLreq.send sReq

If XMLreq.Status = 207 Then MsgBox &quot;Success&quot; End If

End Sub </li> Run the project.</li></ol>

<div class="references_section">