Setting Multivalued Properties (WebDAV)
Setting Multivalued Properties (WebDAV)
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
The following WebDAV PROPPATCH Method request sets the expected-content-class Field of a folder to urn:content-classes:message and urn:content-classes:item content classes and the custom content class urn:contentclasses:myclass1.
See Constructing Exchange Store HTTP URLs and Authentication and Security Using WebDAV for more information.
This topic contains Microsoft® Visual Basic® Scripting Edition (VBScript), Microsoft C#, and Visual Basic .NET code examples.
PROPPATCH /public/docs/ HTTP/1.1 Content-Type: text/xml; charset="UTF-8" <?xml version="1.0"?> <a:propertyupdate xmlns:a="DAV:" xmlns:d="urn:schemas-microsoft-com:exch-data:" xmlns:b="urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/" xmlns:c="xml:"> <a:set> <a:prop> <d:expected-content-class b:dt="mv.string"> <c:v>urn:content-classes:message</c:v> <c:v>urn:content-classes:myclass1</c:v> <c:v>urn:content-classes:item</c:v> </d:expected-content-class> </a:prop> </a:set> </a:propertyupdate>
VBScript
The following WebDAV PROPPATCH Method request sets the expected-content-class Field of a folder to urn:content-classes:message and urn:content-classes:item content classes and the custom content class urn:contentclasses:myclass1.
Option Explicit ' Variables. Dim strSrcURI ' As String Dim strUserName ' As String Dim strPassword ' As String Dim strBody ' As String Dim req ' As Msxml2.XMLHTTP ' Initialize variables. strSrcURI = "https://server/TestStore/TestFolder1/" strUserName = "Domain\UserName" strPassword = "!Password" ' Build the request body. strBody = "<?xml version=""1.0""?>" strBody = strBody & "<a:propertyupdate xmlns:a=""DAV:"" xmlns:d=""urn:schemas-microsoft-com:exch-data:"" " strBody = strBody & "xmlns:b=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" xmlns:c=""xml:"">" strBody = strBody & "<a:set><a:prop><d:expected-content-class b:dt=""mv.string"">" strBody = strBody & "<c:v>urn:content-classes:message</c:v>" strBody = strBody & "<c:v>urn:content-classes:item</c:v>" strBody = strBody & "<c:v>urn:content-classes:myclass1</c:v>" strBody = strBody & "</d:expected-content-class></a:prop>" strBody = strBody & "</a:set></a:propertyupdate>" ' Initialize the XMLHTTP request object. Set req = CreateObject("Microsoft.xmlhttp") ' Open the request object with the PROPPATCH method and ' specify that it will be sent asynchronously. req.open "PROPPATCH", strSrcURI, False, strUserName, strPassword ' Set the Content-Type header to the destination URL. req.setRequestHeader "Content-type", "text/xml" 'Send the PROPPATCH method request. req.send strBody ' An error occurred on the server. If req.status >= 500 Then wscript.echo "Status: " & req.status wscript.echo "Status text: An error occurred on the server." ' Success. ElseIf req.status = 207 Then wscript.echo "Multi-valued property set successfully." Else wscript.echo "Status: " & req.status wscript.echo "Status text: " & req.statustext End If Set req = nothing
C#
The following WebDAV PROPPATCH Method request sets the expected-content-class Field of a folder to urn:content-classes:message and urn:content-classes:item content classes and the custom content class urn:contentclasses:myclass1.
using System; using System.Net; using System.Text; namespace ExchangeSDK.Snippets.CSharp { class SettingMultiValuedPropertiesWebDAV { [STAThread] static void Main(string[] args) { // Variables. System.Net.HttpWebRequest Request; System.Net.WebResponse Response; System.Net.CredentialCache MyCredentialCache; string strSrcURI = "https://server/TestStore/TestFolder/"; string strUserName = "UserName"; string strPassword = "!Password"; string strDomain = "Domain"; string strBody =""; byte[] bytes = null; System.IO.Stream RequestStream; try { // Build the PROPPATCH request body. strBody = "<?xml version=\"1.0\"?>" + "<a:propertyupdate xmlns:a=\"DAV:\" xmlns:d=\"urn:schemas-microsoft-com:exch-data:\" " + "xmlns:b=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" xmlns:c=\"xml:\">" + "<a:set><a:prop><d:expected-content-class b:dt=\"mv.string\">" + "<c:v>urn:content-classes:message</c:v>" + "<c:v>urn:content-classes:item</c:v>" + "<c:v>urn:content-classes:myclass1</c:v>" + "</d:expected-content-class></a:prop>" + "</a:set></a:propertyupdate>"; // Create a new CredentialCache object and fill it with the network // credentials required to access the server. MyCredentialCache = new System.Net.CredentialCache(); MyCredentialCache.Add( new System.Uri(strSrcURI), "NTLM", new System.Net.NetworkCredential(strUserName, strPassword, strDomain) ); // Create the HttpWebRequest object. Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strSrcURI); // Add the network credentials to the request. Request.Credentials = MyCredentialCache; // Specify the method. Request.Method = "PROPPATCH"; // Encode the body using UTF-8. bytes = Encoding.UTF8.GetBytes((string)strBody); // Set the content header length. This must be // done before writing data to the request stream. Request.ContentLength = bytes.Length; // Get a reference to the request stream. RequestStream = Request.GetRequestStream(); // Write the XML body to the request stream. RequestStream.Write(bytes, 0, bytes.Length); // Close the Stream object to release the connection // for further use. RequestStream.Close(); // Set the content type header. Request.ContentType = "text/xml"; // Send the PROPPATCH method request and get the // response from the server. Response = (HttpWebResponse)Request.GetResponse(); Console.WriteLine("Multi-valued property set successfully."); // Clean up. Response.Close(); } catch(Exception ex) { // Catch any exceptions. Any error codes from the PROPPATCH // method request on the server will be caught here, also. Console.WriteLine(ex.Message); } } } }
Visual Basic .NET
The following WebDAV PROPPATCH Method request sets the expected-content-class Field of a folder to urn:content-classes:message and urn:content-classes:item content classes and the custom content class urn:contentclasses:myclass1.
Option Explicit On Option Strict On Module Module1 Sub Main() ' Variables. Dim Request As System.Net.HttpWebRequest Dim Response As System.Net.HttpWebResponse Dim MyCredentialCache As System.Net.CredentialCache Dim strPassword As String Dim strDomain As String Dim strUserName As String Dim strSrcURI As String Dim strBody As String Dim bytes() As Byte Dim RequestStream As System.IO.Stream Try ' Initialize variables. strUserName = "UserName" strPassword = "!Password" strDomain = "Domain" strSrcURI = "https://server/TestStore/TestFolder/" ' Build the PROPPATCH request body. strBody = "<?xml version=""1.0""?>" & _ "<a:propertyupdate xmlns:a=""DAV:"" xmlns:d=""urn:schemas-microsoft-com:exch-data:"" " & _ "xmlns:b=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" xmlns:c=""xml:"">" & _ "<a:set><a:prop><d:expected-content-class b:dt=""mv.string"">" & _ "<c:v>urn:content-classes:message</c:v>" & _ "<c:v>urn:content-classes:item</c:v>" & _ "<c:v>urn:content-classes:myclass1</c:v>" & _ "</d:expected-content-class></a:prop>" & _ "</a:set></a:propertyupdate>" ' Create a new CredentialCache object and fill it with the network ' credentials required to access the server. MyCredentialCache = New System.Net.CredentialCache MyCredentialCache.Add(New System.Uri(strSrcURI), _ "NTLM", _ New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _ ) ' Create the HttpWebRequest object. Request = CType(System.Net.WebRequest.Create(strSrcURI), _ System.Net.HttpWebRequest) ' Add the network credentials to the request. Request.Credentials = MyCredentialCache ' Specify the PROPPATCH method. Request.Method = "PROPPATCH" ' Encode the body using UTF-8. bytes = System.Text.Encoding.UTF8.GetBytes(strBody) ' Set the content header length. This must be ' done before writing data to the request stream. Request.ContentLength = bytes.Length ' Get a reference to the request stream. RequestStream = Request.GetRequestStream() ' Write the message body to the request stream. RequestStream.Write(bytes, 0, bytes.Length) ' Close the Stream object to release the connection ' for further use. RequestStream.Close() ' Set the Content Type header. Request.ContentType = "text/xml" ' Send the PROPPATCH method request and get the ' response from the server. Response = CType(Request.GetResponse(), System.Net.HttpWebResponse) Console.WriteLine("Multi-valued property set successfully.") ' Close the HttpWebResponse object. Response.Close() Catch ex As Exception ' Catch any exceptions. Any error codes from the ' PROPPATCH method requests on the server will be caught ' here, also. Console.WriteLine(ex.Message) End Try End Sub End Module
Related Topics
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
This topic last updated: March 2004
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.