Bonjours tout le monde j'ai un petit souci avec un script qui devrais normalement crée un nouveau rdv dans mon server exchange via une méthode webdav "Propatch", la méthode fonctionnne car je l'ai déja utilisé pour crée un contacte, mais pour les rdv il me renvoie une erreur 400 (demande incorecte), je pense que le problème vien des multistatus que je récupère dans mon xml.
Voici mon code...
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148 Dim strExchSvrName As String Dim strMailbox As String Dim strCalendarUri As String Dim strApptItem As String Dim strDomain As String Dim strUserName As String Dim strPassword As String Dim strApptRequest As String Dim strMailInfo As String Dim strCalInfo 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 = "********" ' Mailbox folder name. strMailbox = "*******" ' Appointment item. strApptItem = "*******.eml" ' URI of the user's calendar folder. strCalendarUri = "http://" & strExchSvrName & "/exchange/" & _ strMailbox & "/Calendar/" ' User name and password of appointment creator. strUserName = "*********" strDomain = "************" strPassword = "**************" ' XML namespace info for the WebDAV request. 'strXMLNSInfo = "xmlns:g->a=""DAV:"" " & _ ' "xmlns:e->f=""http://schemas.microsoft.com/exchange/"" " & _ ' "xmlns:mapi=""http://schemas.microsoft.com/mapi/"" " & _ ' "xmlns:mapit=""http://schemas.microsoft.com/mapi/proptag/"" " & _ ' "xmlns:x->c=""xml:"" " & _ ' "xmlns:cal->d=""urn:schemas:calendar:"" " & _ ' "xmlns:dt->b=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" " & _ ' "xmlns:header->j=""urn:schemas:mailheader:"" " & _ ' "xmlns:mail->e=""urn:schemas:httpmail:""" strXMLNSInfo = "xmlns:a=""DAV:"" " & _ "xmlns:f=""http://schemas.microsoft.com/exchange/"" " & _ "xmlns:d=""urn:schemas:calendar:"" " & _ "xmlns:b=""urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/"" " & _ "xmlns:j=""urn:schemas:mailheader:"" " & _ "xmlns:e=""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 = "<d:location>Dixon</d:location>" & _ "<d:dtstart>2006-05-25T04:00:00.000Z</d:dtstart>" & _ "<d:dtend >2006-05-28T04:00:00.000Z</d:dtend>" & _ "<d:meetingstatus>TENTATIVE</d:meetingstatus>" & _ "<d:instancetype>0</d:instancetype>" & _ "<d:busystatus>FREE</d:busystatus>" & _ "<d:alldayevent>1</d:alldayevent>" & _ "<d:responserequested>0</d:responserequested>" ' Set the required attendee of the appointment. strHeaderInfo = "<j:subject>test</j:subject>" ' Set the subject of the appointment. strMailInfo = "<e:subject>Webdav Appointment</e:subject>" & _ "<e:normalizedsubject>test</e:normalizedsubject>" & _ "<e:hasattachment>0</e:hasattachment>" & _ "<e:textdescription>bla bla bla</e:textdescription>" & _ "<e:htmldescription>Test Appointment Body</e:htmldescription>" ' Build the XML body of the PROPPATCH request. strApptRequest = "<?xml version=""1.0""?>" & _ "<a:propertyupdate " & strXMLNSInfo & ">" & _ "<a:set>" & _ "<g:prop>" & _ "<a:contentclass>urn:content-classes:appointment</a:contentclass>" & _ "<f:outlookmessageclass>IPM.Appointment</f:outlookmessageclass>" & _ strMailInfo & _ strCalInfo & _ strHeaderInfo & _ "</a:prop>" & _ "</a:set>" & _ "</a: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(strCalendarUri), _ "NTLM", New System.Net.NetworkCredential(strUserName, strPassword, strDomain)) ' 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.") ' 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) MsgBox(ex.Message) End Try End Sub
Partager