Answered by:
Exchange 2007 WebDAV Calendar

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,
Jesperstring 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
-
Ask in a forum here: http://social.technet.microsoft.com/Forums/en-US/category/exchangeserver/
Thanks!
Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)
- Proposed as answer by Ed Price - MSFTMicrosoft employee Saturday, January 5, 2013 6:56 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Wednesday, January 16, 2013 1:47 AM
Saturday, January 5, 2013 6:56 AM -
Specifically, in the Exchange Server 2013 - Development forum.
(ignore the Exchange Server 2013 part, they will help with any version)
Karl
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
My Blog: http://unlockpowershell.wordpress.com
My Book: Windows PowerShell 2.0 Bible
My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})- Marked as answer by Ed Price - MSFTMicrosoft employee Wednesday, January 16, 2013 1:48 AM
Monday, January 7, 2013 6:21 PM
All replies
-
Hi,
The question relating to Exchange is beyond the scope of c# forum , I'm moving the thread to : where is the forum for ... forum.
The experts there will direct you to the right place for it.
Thanks,
Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.Friday, December 4, 2009 6:34 AM -
Ask in a forum here: http://social.technet.microsoft.com/Forums/en-US/category/exchangeserver/
Thanks!
Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)
- Proposed as answer by Ed Price - MSFTMicrosoft employee Saturday, January 5, 2013 6:56 AM
- Marked as answer by Ed Price - MSFTMicrosoft employee Wednesday, January 16, 2013 1:47 AM
Saturday, January 5, 2013 6:56 AM -
Specifically, in the Exchange Server 2013 - Development forum.
(ignore the Exchange Server 2013 part, they will help with any version)
Karl
When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer
My Blog: http://unlockpowershell.wordpress.com
My Book: Windows PowerShell 2.0 Bible
My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})- Marked as answer by Ed Price - MSFTMicrosoft employee Wednesday, January 16, 2013 1:48 AM
Monday, January 7, 2013 6:21 PM