Microsoft KB Archive/314198

= How to use the HttpWebRequest class and the HttpWebResponse class to modify the properties of an object in Visual Basic .NET =

Article ID: 314198

Article Last Modified on 4/16/2004

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Exchange 2000 Server Standard Edition

-



This article was previously published under Q314198





For a Microsoft Visual C# .NET version of this article, see 313126.



INTRODUCTION
This article describes how to use the HttpWebRequest class and the HttpWebResponse class from the System.Net namespace to modify the urn:schemas:mailheader:subject property. You can do this for an item in Microsoft Exchange 2000 Server by using Microsoft Visual Basic .NET.



MORE INFORMATION
 Start Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. Under Visual Basic Projects types, click Console Application

By default, Module1.vb is created.  Replace all the code in the code window with the following code: Imports System.Net Imports System.IO

Module Module1 Sub Main ' TODO: Replace with the URL of an object on the Exchange Server. Dim sUri As String = &quot;http://ExchServer/Public/MyFolder/Test.EML&quot;

Dim myUri As System.Uri = New System.Uri(sUri) Dim HttpWRequest As HttpWebRequest = WebRequest.Create(myUri)

' TODO: Change the Subject to &quot;ModifiedSubject&quot;. Dim sQuery As String sQuery = &quot;&quot; & _ &quot;&quot; & _ &quot;<a:prop>&quot; & _ &quot;<m:subject>&quot; & &quot;ModifiedSubject&quot; & &quot;</m:subject>&quot; & _ &quot;</a:prop></a:set>&quot; & _ &quot;</a:propertyupdate>&quot;

' TODO: Replace with the appropriate user credentials. Dim myCred As NetworkCredential = New NetworkCredential(&quot;Domain\UserName&quot;, &quot;Password&quot;) Dim MyCredentialCache As CredentialCache = New CredentialCache MyCredentialCache.Add(myUri, &quot;Basic&quot;, myCred) HttpWRequest.Credentials = MyCredentialCache

' Set the Headers. HttpWRequest.KeepAlive = False HttpWRequest.Headers.Set(&quot;Pragma&quot;, &quot;no-cache&quot;) HttpWRequest.Headers.Set(&quot;Translate&quot;, &quot;f&quot;) HttpWRequest.ContentType = &quot;text/xml&quot; HttpWRequest.ContentLength = sQuery.Length 'Set the request timeout to 5 minutes. HttpWRequest.Timeout = 300000 ' Set the request method. HttpWRequest.Method = &quot;PROPPATCH&quot;

' Store the data in a byte array. Dim ByteQuery As Byte = System.Text.Encoding.ASCII.GetBytes(sQuery) HttpWRequest.ContentLength = ByteQuery.Length Dim QueryStream As Stream = HttpWRequest.GetRequestStream ' Write the data to be posted to the Request Stream. QueryStream.Write(ByteQuery, 0, ByteQuery.Length) QueryStream.Close

' Send the Request and Get the Response. Dim HttpWResponse As HttpWebResponse = HttpWRequest.GetResponse

' Get the Status and the Headers. Dim iStatCode As Integer = HttpWResponse.StatusCode Dim sStatus As String = iStatCode.ToString Console.WriteLine(&quot;Status: {0} {1}&quot;, sStatus, HttpWResponse.StatusDescription.ToString)

Console.WriteLine(&quot;Request Headers:&quot;) Console.WriteLine(HttpWRequest.Headers.ToString) Console.WriteLine(&quot;Response Headers:&quot;) Console.WriteLine(HttpWResponse.Headers.ToString)

' Get the Response Stream. Dim strm As Stream = HttpWResponse.GetResponseStream

' Read the Response Stream. Dim sr As StreamReader = New StreamReader(strm) Dim sText As String = sr.ReadToEnd Console.WriteLine(&quot;Response: {0}&quot;, sText)

' Close the Stream. strm.Close

' Clean up. HttpWRequest = Nothing HttpWResponse = Nothing MyCredentialCache = Nothing myCred = Nothing strm = Nothing sr = Nothing End Sub End Module </li> Modify the previous code on the lines where you see TODO.</li> Press F5 to build and to run the program.</li> Verify that the subject of the specified item has been changed.</li></ol>

Additional query words: webdav

Keywords: kbhowto KB314198

-

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

© Microsoft Corporation. All rights reserved.