Microsoft KB Archive/310283

= How to retrieve and modify properties on items by using WebDAV in Visual C# =

Article ID: 310283

Article Last Modified on 1/19/2006

-

APPLIES TO


 * Microsoft Visual C# 2005 Express Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition
 * Microsoft XML Core Services 4.0
 * Microsoft XML Core Services 4.0

-



This article was previously published under Q310283



INTRODUCTION
This article describes how to use Microsoft XML v3.0 and Microsoft XML v4.0 to retrieve and to modify properties on items in Microsoft Visual C#.



MORE INFORMATION
 Start Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, click New, and then click Project. Under Visual C# Projects, click Console Application.

Note In Visual Studio 2005, click Visual C# under Visual C# Projects.

In Visual Studio .NET, Class1.cs is created by default. In Visual Studio 2005, Program.cs is created by default. Add a reference to Microsoft XML v3.0 or to Microsoft XML v4.0. To do this, follow these steps:  On the Project menu, click Add Reference. On the COM tab, click Microsoft XML v3.0 or Microsoft XML v4.0, and then click Select.

Note In Visual Studio 2005, you do not have to click Select. In the Add References dialog box, click OK to accept your selections.</li> Click Yes if you receive a message to generate wrappers for the libraries that you selected.</li></ol> </li>  You can use the following sample code to retrieve properties: using System;

namespace WebDav {   class Class1 {          public static void Main(String [] args) {           try {                      MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30; // TODO: Replace with your message URL. String sUrl = &quot;http://ExchServer/public/MyApplication/Test.eml&quot;; //TODO: Replace to reflect your USERID and Password. oXMLHttp.open(&quot;PROPFIND&quot;, sUrl, false, &quot;UserDomain\UserAlias&quot;, &quot;UserPassword&quot;); // TODO:

String sQuery;

sQuery = &quot;<?xml version='1.0'?>&quot; + &quot;<a:propfind xmlns:a='DAV:' xmlns:m='urn:schemas:mailheader:'>&quot; + &quot;<a:prop>&quot; + &quot;<m:subject/>&quot; + &quot;</a:prop>&quot; + &quot;</a:propfind>&quot;;

oXMLHttp.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml&quot;); oXMLHttp.send(sQuery);

Console.WriteLine(oXMLHttp.status); Console.WriteLine(oXMLHttp.statusText); Console.WriteLine(oXMLHttp.responseText); }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }

}        } }                    </li>  You can use the following sample code to modify properties: using System; using System.Reflection;

namespace WebDav {   class Class1 {          public static void Main(String [] args) {           try {                      MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30; // TODO : Replace with your message URL. String sUrl = &quot;http://ExchServer/public/MyApplication/Test.eml&quot;; // TODO : Replace to reflect your USERID and Password. oXMLHttp.open(&quot;PROPPATCH&quot;, sUrl, false, &quot;UserDomain\UserAlias&quot;, &quot;UserPassword&quot;); // TODO:

String sQuery;

sQuery = &quot;<?xml version='1.0'?>&quot; + &quot;<a:propertyupdate xmlns:a='DAV:' &quot; + &quot;xmlns:m='urn:schemas:mailheader:'>&quot; + &quot;<a:set><a:prop>&quot; + &quot;<m:subject>&quot; + &quot;ModifiedSubject&quot; + &quot;</m:subject>&quot; + &quot;</a:prop></a:set>&quot; + &quot;</a:propertyupdate>&quot;;

oXMLHttp.setRequestHeader(&quot;Content-Type&quot;, &quot;text/xml&quot;); //oXMLHttp.setRequestHeader(&quot;Content-Length&quot;, \&quot;&quot; + sQuery.Length); oXMLHttp.send(sQuery);

Console.WriteLine(oXMLHttp.status); Console.WriteLine(oXMLHttp.statusText); Console.WriteLine(oXMLHttp.responseText); }           catch (Exception e)            { Console.WriteLine(&quot;{0} Exception caught.&quot;, e); }

}        } }                    </li> Modify the previous sample code to add your information. Put your information on the lines where you see TODO.</li> Press F5 to build and to run the program.</li> Verify that the response gives you the property that you specified.</li></ol>

Additional query words: Microsoft XML v3.0/v4.0 retrieve modify properties Items

Keywords: kbhowto kbmsg kbxml kbcode KB310283

-

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

© Microsoft Corporation. All rights reserved.