Groups > EMAIL > Microsoft Solution for Hosted Exchange > Problem with creating appointment on Exchange Server 2003 using WebDav




Problem with creating appointment on Exchange Server 2003
using WebDav

Problem with creating appointment on Exchange Server 2003 using WebDav
Tue, 1 Apr 2008 17:07:32 +0000
The code below, I have gotten it to work with Exchange Server 2007 to add
appointment to a specific user account. When I try it with Exchange Server 2003,
it doesn't work. It gives an error: The remote server returned an error: (405)
Method Not Allowed. The WebDav is turn on. 

But, when I try the method, "PUT", the code runs all the way through
without any errors but it doesn't add the appointment into the user account. 

What is the problem with my solution?

Thanks!

 

Try

' Exchange server namestrExchSvrName =
ConfigurationManager.AppSettings("ES_ServerName")

' Mailbox folder name.

strMailbox = ConfigurationManager.AppSettings("ES_UserName")

' Appointment item.

strApptItem = "Test.eml"

' URI of the user's calendar folder.

Dim strBaseUri = "https://" & strExchSvrName &
"/exchange/"

strCalendarUri = "https://" & strExchSvrName &
"/exchange/" & strMailbox &
"/Calendar/"System.Net.ServicePointManager.ServerCertificateValidation
Callback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf
AcceptAllCerts)

' User name and password of appointment creator.strUserName =
ConfigurationManager.AppSettings("ES_UserName")

strDomain =
ConfigurationManager.AppSettings("WindowsDomain")strPassword =
ConfigurationManager.AppSettings("ES_Pwd")

' XML namespace info for the WebDAV request.strXMLNSInfo =
"xmlns:g=""DAV:"" " & _

"xmlns:e=""http://schemas.microsoft.com/exchange/""
" &
_"xmlns:mapi=""http://schemas.microsoft.com/mapi/""
" & _

"xmlns:mapit=""http://schemas.microsoft.com/mapi/proptag/"&q
uot; " & _"xmlns:x=""xml:""
xmlns:cal=""urn:schemas:calendar:"" " & _

"xmlns:dt=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"&
quot; " &
_"xmlns:header=""urn:schemas:mailheader:"" " &
_

"xmlns:mail=""urn:schemas:httpmail:"""

' Set the appointment item properties. The reminder time is set in seconds.

' To create an all-day meeting, set the dtstart/dtend range for 24 hours

' or more and set the alldayevent property to 1. See the documentation

' on the properties in the urn:schemas:calendar: namespace for more
information.strCalInfo = "<cal:location>meetappt
Location</cal:location>" & _

"<cal:dtstart
dt:dt=""dateTime.tz"">2008-03-13T19:00:00.000Z</cal:dt
start>" & _"<cal:dtend
dt:dt=""dateTime.tz"">2008-03-13T19:30:00.000Z</cal:dt
end>" & _

"<cal:instancetype
dt:dt=""int"">0</cal:instancetype>" &
_"<cal:busystatus>BUSY</cal:busystatus>" & _

"<cal:meetingstatus>CONFIRMED</cal:meetingstatus>" &
_"<cal:alldayevent
dt:dt=""boolean"">0</cal:alldayevent>" &
_

"<cal:responserequested
dt:dt=""boolean"">1</cal:responserequested>"
& _

"<cal:reminderoffset
dt:dt=""int"">900</cal:reminderoffset>"

' Set the required attendee of the appointment.

strHeaderInfo = "<header:to>" & strMailbox &
"</header:to>"

' Set the subject of the appointment.strMailInfo =
"<mail:subject>Test Appointment Subject Chinh2
hah</mail:subject>" & _

"<mail:htmldescription>Let's meet
here</mail:htmldescription>"

' Build the XML body of the PROPPATCH request.strApptRequest = "<?xml
version=""1.0""?>" & _

"<g:propertyupdate " & strXMLNSInfo & ">"
& _"<g:set><g:prop>" & _

"<g:contentclass>urn:content-classes:appointment</g:contentclass&g
t;" &
_"<e:outlookmessageclass>IPM.Appointment</e:outlookmessageclass>
;" & _

strMailInfo & _

strCalInfo & _

strHeaderInfo & _"<mapi:finvited
dt:dt=""boolean"">1</mapi:finvited>" & _

"</g:prop></g:set>" & _

"</g: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(strBaseUri), _"BASIC", _New
System.Net.NetworkCredential(strUserName, strPassword) _

)

'MyCredentialCache.Add(New System.Uri(strBaseUri), _

' "NTLM", _

' New System.Net.NetworkCredential(strUserName, strPassword, strDomain) _

' )

'MyCredentialCache.Add(New System.Uri(strBaseUri), _

' "Digest", _

' New System.Net.NetworkCredential(strUserName, strPassword) _

' )

' Create the HttpWebRequest object.PROPPATCHRequest =
CType(System.Net.HttpWebRequest.Create(strCalendarUri & strApptItem), _

System.Net.HttpWebRequest)

' Add the network credentials to the request.

PROPPATCHRequest.Credentials = MyCredentialCache

' Specify the PROPPATCH method.

PROPPATCHRequest.Method = "PROPPATCH"

' Set the content type header.

PROPPATCHRequest.ContentType = "text/xml"

' Encode the body using UTF-8.

bytes = System.Text.Encoding.UTF8.GetBytes(strApptRequest)

' Set the content header length. This must be

' done before writing data to the request stream.

PROPPATCHRequest.ContentLength = bytes.Length

' Get a reference to the request stream.

PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream()

' Write the message body to the request stream.

PROPPATCHRequestStream.Write(bytes, 0, bytes.Length)

' Close the Stream object to release the connection

' for further use.

PROPPATCHRequestStream.Close()

' Create the appointment in the Calendar folder of the

' user's mailbox.PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(),
System.Net.HttpWebResponse)

'Console.WriteLine("Appointment successfully created.")

lblMsg.Text = "Appointment successfully created."

' Clean up.

PROPPATCHResponse.Close()Catch ex As Exception

' Catch any exceptions. Any error codes from the PROPPATCH

' or MOVE method requests on the server will be caught

' here, also.

'Console.WriteLine(ex.Message)

lblMsg.Text = ex.Message

EndTry
Post Reply
about | contact