Microsoft KB Archive/314192

= How to create an Outlook Calendar folder by using the HttpWebRequest class in Visual Basic 2005 or in Visual Basic .NET =

Article ID: 314192

Article Last Modified on 12/6/2006

-

APPLIES TO


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

-



This article was previously published under Q314192



INTRODUCTION
This article describes how to create a Microsoft Outlook Calendar folder by using the HttpWebRequest class and the HttpWebResponse class of the System.Net namespace. You create the Outlook Calendar folder on a Microsoft Exchange 2000 Server by using Microsoft Visual Basic .NET.



MORE INFORMATION
To create the Outlook Calendar folder, follow these steps:  Start Microsoft Visual Studio 2005 or Microsoft Visual Studio .NET. On the File menu, click New, and then click Project. In the Visual Basic Projects list, select Console Application.

By default, Module1.vb is created.

Note In Visual Studio 2005, the Visual Basic Projects list is named Visual Basic.  In the code window, replace all the code with the following sample code. Imports System.Net Imports System.IO

Module Module1 Sub Main 'strFolderType   Name '       'MailItems        IPF.Note 'ContactItems    IPF.Contact 'AppointmentItems IPF.Appointment 'NoteItems       IPF.StickyNote 'TaskItems       IPF.Task 'JournalItems    IPF.Journal

' TODO: Replace with the URL to the new folder. Dim sUri As String = &quot;http://ExchServer/Exchange/Administrator/Inbox/NewFolder&quot;

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

Dim sQuery As String sQuery = &quot;&quot; & _ &quot;&quot; & _ &quot;&quot; & _ &quot;<ex:outlookfolderclass>IPF.Appointment</ex:outlookfolderclass>&quot; & _ &quot;</a:prop></a:set>&quot; & _ &quot;</a:propertyupdate>&quot;

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

'Uncomment the following statement, and then comment the previous four statements if you want to        'use Integrated Windows authentication. 'httpWRequest.Credentials = CredentialCache.DefaultCredentials

'When you use Basic-type authentication, the username and the password are sent as base64-encoded text that is        'easily decoded. Microsoft recommends that you use Basic-type authentication instead of SSL to help protect 'the username and the password.

' Set Headers. httpWRequest.KeepAlive = False httpWRequest.Headers.Set(&quot;Pragma&quot;, &quot;no-cache&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;MKCOL&quot;

' The data must be stored 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 Request and Get Response. Dim httpWResponse As HttpWebResponse = httpWRequest.GetResponse

' Get Status and 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 Response Stream. Dim strm As Stream = httpWResponse.GetResponseStream

' Read the Response Steam. 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 sample code where you see TODO in the sample code.</li> Press F5 to build and to run the program.</li> Verify that the Outlook Calendar folder is created.</li></ol>

Additional query words: exchange folder outlook calendar asp.net aspnet

Keywords: kbvs2005swept kbvs2005applies kbxml kbhowto KB314192

-

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

© Microsoft Corporation. All rights reserved.