Forum des développeurs  

Le forum de référence en programmation et développement. Articles, cours et tutoriels du débutant au chef de projet et DBA confirmé.
Précédent   Forum des développeurs > Hardware, Systèmes et Logiciels > Microsoft Office > Outlook > VBA Outlook

Réponse
 
Outils de la discussion
Vieux 27/03/2008, 15h15   #1 (permalink)
Membre régulier
 
Date d'inscription: février 2008
Messages: 125
Par défaut probléme de création de rdv sous exchange

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...
Code :
 
  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
 
Merci d'avance
djorfe est déconnecté   Envoyer un message privé Réponse avec citation
Vieux 27/03/2008, 16h24   #2 (permalink)
Membre régulier
 
Date d'inscription: février 2008
Messages: 125
Par défaut

Citation:
Envoyé par djorfe Voir le message
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...
Code :
 
  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>" & _
                    "<a: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
 
Merci d'avance
djorfe est déconnecté   Envoyer un message privé Réponse avec citation
Vieux 31/03/2008, 05h55   #3 (permalink)
Membre régulier
 
Date d'inscription: août 2007
Localisation: France, Paris
Messages: 136
Envoyer un message via MSN à Laurent CUENET Envoyer un message via Skype™ à Laurent CUENET
Par défaut

Bonjour,

Je comprends pas pour quoi tu utilises cette méthode qui me paraît un peu compliqué.

A bientôt
Laurent CUENET est déconnecté   Envoyer un message privé Réponse avec citation
NEWS MS-OFFICEFAQs OFFICETUTORIELS OFFICELIVRES OFFICESOURCES VBAACCESS

Réponse

Précédent   Forum des développeurs > Hardware, Systèmes et Logiciels > Microsoft Office > Outlook > VBA Outlook

 
Offres d' emploi informatique sur Lesjeudis.com


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are non
Pingbacks are non
Refbacks are non
Navigation rapide