locked
Exchange 2007 WebDAV Calendar RRS feed

  • Question

  • Hi, I have this code, trying to create a Calendar appointment on Exchange 2007 using WebDAV.
    But the server just returns Conflict 409, anyone having any idea why??

    Thanks,
    Jesper

             string strExchSvrName = "";
             string strMailbox = "";
             string strCalendarUri = "";
             string strApptItem = "";
             string strDomain = "";
             string strUserName = "";
             string strPassword = "";
             string strApptRequest = "";
             string strMailInfo = "";
             string strCalInfo = "";
             string strXMLNSInfo = "";
             string strHeaderInfo = "";
             System.Net.HttpWebRequest PROPPATCHRequest = null;
             System.Net.WebResponse PROPPATCHResponse = null;
             System.Net.CredentialCache MyCredentialCache = null;
             byte[] bytes = null;
             System.IO.Stream PROPPATCHRequestStream = null;
             //try
             //{
                // Exchange server name;
                strExchSvrName = "";
                // Mailbox folder name.
                strMailbox = "";
                // Appointment item.
                strApptItem = "testappointment.eml";
                // URI of the user's calendar folder.
                strCalendarUri = "https://" + strExchSvrName + "/exchange/"
                + strMailbox + "/Calendar/";
                // User name and password of appointment creator.
                strUserName = "";
                strDomain = "";
                strPassword = "";
                // 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/\" "
                + "xmlns:x=\"xml:\" xmlns:cal=\"urn:schemas:calendar:\" "
                + "xmlns:dt=\"urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/\" "
                + "xmlns:header=\"urn:schemas:mailheader:\" "
                + "xmlns:mail=\"urn:schemas:httpmail:\"";
                // Set the appointment item properties.  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\">2009-12-04T23:00:00.000Z</cal:dtstart>"
                + "<cal:dtend dt:dt=\"dateTime.tz\">2009-12-04T23:30:00.000Z</cal:dtend>"
                + "<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>"
                // Set the reminder time (in seconds).
                + "<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</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>"
                + "<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(strCalendarUri),
                                       "NTLM",
                                       new System.Net.NetworkCredential(strUserName, strPassword, strDomain)
                                      );
                // Create the HttpWebRequest object.
                PROPPATCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strCalendarUri + strApptItem);
                // Add the network credentials to the request.
                PROPPATCHRequest.Credentials = MyCredentialCache;
                // Specify the PROPPATCH method.
                PROPPATCHRequest.Method = "PROPPATCH";
                // Encode the body using UTF-8.
                bytes = Encoding.UTF8.GetBytes((string)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();
                // Set the content type header.
                PROPPATCHRequest.ContentType = "text/xml";
                // Create the appointment in the Calendar folder of the
                // user's mailbox.
                PROPPATCHResponse = (System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
                // Clean up.
                PROPPATCHResponse.Close();
                Console.WriteLine("Appointment successfully created.");
    • Moved by Harry Zhu Friday, December 4, 2009 6:34 AM (From:Visual C# General)
    Wednesday, December 2, 2009 6:44 PM

Answers

All replies