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<BR/>
' TODO: Replace with the URL to the new folder.
Dim sUri As String = "http://ExchServer/Exchange/Administrator/Inbox/NewFolder"
Dim myUri As System.Uri = New System.Uri(sUri)
Dim httpWRequest As HttpWebRequest = WebRequest.Create(myUri)
Dim sQuery As String
sQuery = "<?xml version='1.0'?>" & _
"<a:propertyupdate xmlns:a='DAV:' " & _
"xmlns:ex='http://schemas.microsoft.com/exchange/'>" & _
"<a:set><a:prop>" & _
"<ex:outlookfolderclass>IPF.Appointment</ex:outlookfolderclass>" & _
"</a:prop></a:set>" & _
"</a:propertyupdate>"
' Set credentials.
' TODO: Replace with appropriate user credentials.
Dim myCred As NetworkCredential = New NetworkCredential("Domain\User", "Password")
Dim MyCredentialCache As CredentialCache = New CredentialCache()
MyCredentialCache.Add(myUri, "Basic", 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("Pragma", "no-cache")
httpWRequest.ContentType = "text/xml"
httpWRequest.ContentLength = sQuery.Length
'Set the request timeout to 5 minutes.
httpWRequest.Timeout = 300000
' Set the request method.
httpWRequest.Method = "MKCOL"
' 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("Status: {0} {1}", sStatus, httpWResponse.StatusDescription.ToString())
Console.WriteLine("Request Headers:")
Console.WriteLine(httpWRequest.Headers.ToString())
Console.WriteLine("Response Headers:")
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("Response: {0}", sText)
' Close the Stream.
strm.Close()
' Clean up.
httpWRequest = Nothing
httpWResponse = Nothing
MyCredentialCache = Nothing
myCred = Nothing
strm = Nothing
sr = Nothing
End Sub
End Module