Hi - I'm using WebDAV to try and create a Task Item in an Exchange Mailbox -
when I run this code:
Dim strExchSvrName As String
Dim strMailbox As String
Dim strTaskUri As String
Dim strTaskItem As String
Dim strDomain As String
Dim strUserName As String
Dim strPassword As String
Dim strApptRequest As String
Dim strMailInfo As String
Dim strTaskInfo As String
Dim strXMLNSInfo As String
Dim strHeaderInfo As String
Dim PROPPATCHRequest As System.Net.HttpWebRequest
Dim PROPPATCHResponse As System.Net.WebResponse
Dim MyCredentialCache As System.Net.CredentialCache
Dim bytes() As Byte
Dim PROPPATCHRequestStream As System.IO.Stream
Try
' Exchange server name
strExchSvrName = "SACINF02"
' Mailbox folder name.
strMailbox = Environment.UserName
'Take out the Domain name from the Environment User Name
strMailbox = Right(strMailbox, Len(strMailbox) - InStr(strMailbox, "\"))
' Appointment item.
' strApptItem = TaskName & "Task.eml"
' URI of the user's calendar folder.
strTaskUri = " & strExchSvrName & "/exchange/" & _
strMailbox & "/Task/"
' User name and password of appointment creator.
strUserName = strMailbox
strDomain = "SACRAMENTO"
strPassword = "P@ssw0rd"
' XML namespace info for the WebDAV request.
strXMLNSInfo = "xmlns:g=\""DAV:\""" & _
"xmlns:e=\"" & _
"xmlns:mapi=\"" " & _
"xmlns:mapit=\"" & _
"xmlns:dt=\""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\"" " & _
"xmlns:h=\"" & _
"xmlns:i=\"" & _
"xmlns:header=\""urn:schemas:mailheader:\"" " & _
"xmlns:mail=\""urn:schemas:httpmail:\"""
strTaskInfo = "<h:0x00008104 dt:dt=\""dateTime.tz\"">2005-09-29T00:00:00Z</h:0x00008104>" & _
"<h:0x00008105 dt:dt=\""dateTime.tz\"">2005-09-29T00:00:00Z</h:0x00008105>" & _
"<h:0x0000811C dt:dt=\""boolean\"">0</h:0x0000811C>" & _
"<h:0x00008101 dt:dt=\""int\"">0</h:0x00008101>" & _
"<h:0x00008102 dt:dt=\""float\"">0</h:0x00008102>" & _
"<i:0x00008503 dt:dt=\""boolean\"">1</i:0x00008503>"
strHeaderInfo = "<header:to>" & "" & "</header:to>"
strMailInfo = "<mail:subject>Test Task Subject</mail:subject>" & _
"<mail:htmldescription>Test Description</mail:htmldescription>"
'// Build the XML body of the PROPPATCH request.
strApptRequest = "<?xml version=\""1.0\""?>" & _
"<g
ropertyupdate " + strXMLNSInfo + ">" & _
"<g:set><g
rop>" & _
"<g:contentclass>urn:content-classes:task</g:contentclass>" & _
"<e
utlookmessageclass>IPM.Task</e
utlookmessageclass>" & _
strMailInfo & _
strTaskInfo & _
strHeaderInfo & _
"</g
rop></g:set>" & _
"</g
ropertyupdate>"
MyCredentialCache = New System.Net.CredentialCache
MyCredentialCache.Add(New System.Uri(strTaskUri), "NTLM", New System.Net.NetworkCredential(strUserName, strPassword, strDomain))
' Create the HttpWebRequest object.
PROPPATCHRequest = CType(System.Net.HttpWebRequest.Create(strTaskUri & strTaskItem), _
System.Net.HttpWebRequest)
PROPPATCHRequest.Credentials = MyCredentialCache
PROPPATCHRequest.Method = "PROPPATCH"
PROPPATCHRequest.ContentType = "text/xml"
' Encode the body using UTF-8.
bytes = System.Text.Encoding.UTF8.GetBytes(strApptRequest)
PROPPATCHRequest.ContentLength = bytes.Length
PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream()
PROPPATCHRequestStream.Write(bytes, 0, bytes.Length)
PROPPATCHRequestStream.Close()
PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(), System.Net.HttpWebResponse)
PROPPATCHResponse.Close()
MsgBox("Task successfully created.")
Catch ex As Exception
MsgBox(ex.Message)
End Try
I get the following error message on this line:
PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(), System.Net.HttpWebResponse)
Error Message:
"The remote server returned an error: (400) Bad Request"
I am able to successfully add Calendar Appointment to the same Outlook book using similar code (i copied the code from ) - and it worked successfully for Calendar Appointment .
Then I saw the code above on this site:
converted it to VB .NET - ran it and it gives thsi Bad Request error. I'm trying to figure out why.
One thing I noticed is that the Task Property Names in the XMl in this code are coded in hexadecinal (i.e. 0x00008105 etc). why?
Can anyone help me with this one?
when I run this code:
Dim strExchSvrName As String
Dim strMailbox As String
Dim strTaskUri As String
Dim strTaskItem As String
Dim strDomain As String
Dim strUserName As String
Dim strPassword As String
Dim strApptRequest As String
Dim strMailInfo As String
Dim strTaskInfo As String
Dim strXMLNSInfo As String
Dim strHeaderInfo As String
Dim PROPPATCHRequest As System.Net.HttpWebRequest
Dim PROPPATCHResponse As System.Net.WebResponse
Dim MyCredentialCache As System.Net.CredentialCache
Dim bytes() As Byte
Dim PROPPATCHRequestStream As System.IO.Stream
Try
' Exchange server name
strExchSvrName = "SACINF02"
' Mailbox folder name.
strMailbox = Environment.UserName
'Take out the Domain name from the Environment User Name
strMailbox = Right(strMailbox, Len(strMailbox) - InStr(strMailbox, "\"))
' Appointment item.
' strApptItem = TaskName & "Task.eml"
' URI of the user's calendar folder.
strTaskUri = " & strExchSvrName & "/exchange/" & _
strMailbox & "/Task/"
' User name and password of appointment creator.
strUserName = strMailbox
strDomain = "SACRAMENTO"
strPassword = "P@ssw0rd"
' XML namespace info for the WebDAV request.
strXMLNSInfo = "xmlns:g=\""DAV:\""" & _
"xmlns:e=\"" & _
"xmlns:mapi=\"" " & _
"xmlns:mapit=\"" & _
"xmlns:dt=\""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\"" " & _
"xmlns:h=\"" & _
"xmlns:i=\"" & _
"xmlns:header=\""urn:schemas:mailheader:\"" " & _
"xmlns:mail=\""urn:schemas:httpmail:\"""
strTaskInfo = "<h:0x00008104 dt:dt=\""dateTime.tz\"">2005-09-29T00:00:00Z</h:0x00008104>" & _
"<h:0x00008105 dt:dt=\""dateTime.tz\"">2005-09-29T00:00:00Z</h:0x00008105>" & _
"<h:0x0000811C dt:dt=\""boolean\"">0</h:0x0000811C>" & _
"<h:0x00008101 dt:dt=\""int\"">0</h:0x00008101>" & _
"<h:0x00008102 dt:dt=\""float\"">0</h:0x00008102>" & _
"<i:0x00008503 dt:dt=\""boolean\"">1</i:0x00008503>"
strHeaderInfo = "<header:to>" & "" & "</header:to>"
strMailInfo = "<mail:subject>Test Task Subject</mail:subject>" & _
"<mail:htmldescription>Test Description</mail:htmldescription>"
'// Build the XML body of the PROPPATCH request.
strApptRequest = "<?xml version=\""1.0\""?>" & _
"<g
"<g:set><g
"<g:contentclass>urn:content-classes:task</g:contentclass>" & _
"<e
strMailInfo & _
strTaskInfo & _
strHeaderInfo & _
"</g
"</g
MyCredentialCache = New System.Net.CredentialCache
MyCredentialCache.Add(New System.Uri(strTaskUri), "NTLM", New System.Net.NetworkCredential(strUserName, strPassword, strDomain))
' Create the HttpWebRequest object.
PROPPATCHRequest = CType(System.Net.HttpWebRequest.Create(strTaskUri & strTaskItem), _
System.Net.HttpWebRequest)
PROPPATCHRequest.Credentials = MyCredentialCache
PROPPATCHRequest.Method = "PROPPATCH"
PROPPATCHRequest.ContentType = "text/xml"
' Encode the body using UTF-8.
bytes = System.Text.Encoding.UTF8.GetBytes(strApptRequest)
PROPPATCHRequest.ContentLength = bytes.Length
PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream()
PROPPATCHRequestStream.Write(bytes, 0, bytes.Length)
PROPPATCHRequestStream.Close()
PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(), System.Net.HttpWebResponse)
PROPPATCHResponse.Close()
MsgBox("Task successfully created.")
Catch ex As Exception
MsgBox(ex.Message)
End Try
I get the following error message on this line:
PROPPATCHResponse = CType(PROPPATCHRequest.GetResponse(), System.Net.HttpWebResponse)
Error Message:
"The remote server returned an error: (400) Bad Request"
I am able to successfully add Calendar Appointment to the same Outlook book using similar code (i copied the code from ) - and it worked successfully for Calendar Appointment .
Then I saw the code above on this site:
converted it to VB .NET - ran it and it gives thsi Bad Request error. I'm trying to figure out why.
One thing I noticed is that the Task Property Names in the XMl in this code are coded in hexadecinal (i.e. 0x00008105 etc). why?
Can anyone help me with this one?