|
|
|
date: Thu, 19 Jan 2006 07:59:04 -0800,
group: microsoft.public.exchange2000.development
back
409 Error when modifying existing appointment
I am trying to write a function to modify existing appointments in Exchange,
using WebDAV.
No matter what I do, I always get a 409 (Conflict) Message. Below find my
code. As you can see, I have commented out almost all of the field updates,
and limited it to the subject and location.
Thanks,
Toine
public override void UpdateAppointment(string RoomID, string
strConnectionInfo, DateTime dtStart, DateTime dtEnd, string strSubject,
string strLocation, string strComments, string strRRule, string strItemID,
string strUserName, string strPassword, string strDomain)
{
if (strConnectionInfo.EndsWith("/"))
{
}
else
{
strConnectionInfo += "/";
}
string strApptRequest = "";
string strMailInfo = "";
string strCalInfo = "";
string strXMLNSInfo = "";
string strHeaderInfo = "";
string strApptItem = "";
System.Net.HttpWebRequest PROPPATCHRequest = null;
System.Net.WebResponse PROPPATCHResponse = null;
System.Net.CredentialCache MyCredentialCache = null;
byte[] bytes = null;
System.IO.Stream PROPPATCHRequestStream = null;
string strEndDate =
string.Format("{0}-{1:D2}-{2:D2}T{3:D2}:{4:D2}:{5:D2}Z", dtEnd.Year,
dtEnd.Month, dtEnd.Day, dtEnd.Hour, dtEnd.Minute, dtEnd.Second);
string strStartDate =
string.Format("{0}-{1:D2}-{2:D2}T{3:D2}:{4:D2}:{5:D2}Z", dtStart.Year,
dtStart.Month, dtStart.Day, dtStart.Hour, dtStart.Minute, dtStart.Second);
int instancetype = 0;
if (strRRule == null)
{
instancetype = 0;
}
else
{
instancetype = 1;
}
try
{
Debug.Write(String.Format("Subject: {0} - ",strSubject));
// Appointment item.
strApptItem = strItemID;
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:\"";
strCalInfo = "<cal:location>" + strLocation +
"</cal:location>";
//+ "<cal:dtstart dt:dt=\"dateTime.tz\">" + strStartDate
+ "</cal:dtstart>"
// + "<cal:dtstart>" + strStartDate + "</cal:dtstart>"
//+ "<cal:dtend dt:dt=\"dateTime.tz\">" + strEndDate +
"</cal:dtend>"
// + "<cal:dtend>" + strEndDate + "</cal:dtend>"
// + "<cal:instancetype dt:dt=\"int\">" +
instancetype.ToString() + "</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\">0</cal:responserequested>";
/* if (strRRule == null)
{
}
else
{
strCalInfo += "<cal:rrule dt:dt=\"mv.string\">"
+ "<x:v>" + strRRule + "</x:v>"
+ "</cal:rrule>";
}
*/ // Set the required attendee of the appointment.
// strHeaderInfo = "<header:to>" + strMailbox +
"</header:to>";
strHeaderInfo = "";
strMailInfo = "<mail:subject>" + strSubject +
"</mail:subject>";
//+ "<mail:htmldescription>" + strComments +
"</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.
// Create the HttpWebRequest object.
PROPPATCHRequest =
(System.Net.HttpWebRequest)HttpWebRequest.Create(strConnectionInfo +
strApptItem);
// PROPPATCHRequest.Headers.Add("Overwrite", "T");
if (strUserName == null)
{
MyCredentialCache =
(CredentialCache)CredentialCache.DefaultCredentials;
}
else
{
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add(new System.Uri(strConnectionInfo),
"NTLM",
new
System.Net.NetworkCredential(strUserName, strPassword, strDomain)
);
// 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();
// Set the content type header.
PROPPATCHRequest.ContentType = "text/xml";
PROPPATCHRequest.Headers.Set("Overwrite", "t");
PROPPATCHRequest.Headers.Set("Translate", "f");
PROPPATCHRequest.Headers.Set("Pragma", "no-cache");
// 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 =
(System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
// Clean up.
PROPPATCHResponse.Close();
if (strRRule != null)
{
this.GenerateRecurInstances(RoomID, strConnectionInfo,
dtStart, dtEnd, strSubject, strLocation, strComments, strRRule, strUserName,
strPassword, strDomain);
}
string x = this.FindMeetingUID(strConnectionInfo +
strApptItem, MyCredentialCache);
SqlConnection sqlConn = new
SqlConnection("Server=Roomviewdev.crestron.com;Initial
Catalog=CrestronRoomView;User ID=sa;Password=S0ftw4re;");
//SqlConnection sqlConn = new
SqlConnection("Server=ns1.dstldns.net;Initial Catalog=CrestronRoomView;User
ID=adam;Password=naomi;");
SqlCommand sqlCommand = new SqlCommand("CRV_AddNewMeeting",
sqlConn);
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.Add("@GroupwareMeetingID", x);
sqlCommand.Parameters.Add("@MeetingComment", "");
sqlCommand.Parameters.Add("@isEditable", 1);
sqlCommand.Parameters.Add("@RoomViewMeetingID",
System.Guid.NewGuid().ToString());
sqlConn.Open();
sqlCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
date: Thu, 19 Jan 2006 07:59:04 -0800
author: Toine C. Leerentveld Toine C.
Re: 409 Error when modifying existing appointment
Be sure that you use non-existing appointment URL in line:
PROPPATCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strConnectionInfo + strApptItem);
Michael
-------------------------------
If you need WebDAV API for Exchange server,
use our component WebDAV .NET for Exchange.
Check out http://www.independentsoft.com
"Toine C. Leerentveld" <Toine C. Leerentveld@discussions.microsoft.com> wrote in message news:459771DC-C42B-40AF-9911-A04DA26EA007@microsoft.com...
> I am trying to write a function to modify existing appointments in Exchange,
> using WebDAV.
>
> No matter what I do, I always get a 409 (Conflict) Message. Below find my
> code. As you can see, I have commented out almost all of the field updates,
> and limited it to the subject and location.
>
> Thanks,
>
> Toine
>
> public override void UpdateAppointment(string RoomID, string
> strConnectionInfo, DateTime dtStart, DateTime dtEnd, string strSubject,
> string strLocation, string strComments, string strRRule, string strItemID,
> string strUserName, string strPassword, string strDomain)
> {
> if (strConnectionInfo.EndsWith("/"))
> {
> }
> else
> {
> strConnectionInfo += "/";
> }
> string strApptRequest = "";
> string strMailInfo = "";
> string strCalInfo = "";
> string strXMLNSInfo = "";
> string strHeaderInfo = "";
> string strApptItem = "";
> System.Net.HttpWebRequest PROPPATCHRequest = null;
> System.Net.WebResponse PROPPATCHResponse = null;
> System.Net.CredentialCache MyCredentialCache = null;
> byte[] bytes = null;
> System.IO.Stream PROPPATCHRequestStream = null;
> string strEndDate =
> string.Format("{0}-{1:D2}-{2:D2}T{3:D2}:{4:D2}:{5:D2}Z", dtEnd.Year,
> dtEnd.Month, dtEnd.Day, dtEnd.Hour, dtEnd.Minute, dtEnd.Second);
> string strStartDate =
> string.Format("{0}-{1:D2}-{2:D2}T{3:D2}:{4:D2}:{5:D2}Z", dtStart.Year,
> dtStart.Month, dtStart.Day, dtStart.Hour, dtStart.Minute, dtStart.Second);
> int instancetype = 0;
> if (strRRule == null)
> {
> instancetype = 0;
> }
> else
> {
> instancetype = 1;
> }
> try
> {
> Debug.Write(String.Format("Subject: {0} - ",strSubject));
> // Appointment item.
> strApptItem = strItemID;
>
> 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:\"";
> strCalInfo = "<cal:location>" + strLocation +
> "</cal:location>";
> //+ "<cal:dtstart dt:dt=\"dateTime.tz\">" + strStartDate
> + "</cal:dtstart>"
> // + "<cal:dtstart>" + strStartDate + "</cal:dtstart>"
> //+ "<cal:dtend dt:dt=\"dateTime.tz\">" + strEndDate +
> "</cal:dtend>"
> // + "<cal:dtend>" + strEndDate + "</cal:dtend>"
> // + "<cal:instancetype dt:dt=\"int\">" +
> instancetype.ToString() + "</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\">0</cal:responserequested>";
> /* if (strRRule == null)
> {
> }
> else
> {
> strCalInfo += "<cal:rrule dt:dt=\"mv.string\">"
> + "<x:v>" + strRRule + "</x:v>"
> + "</cal:rrule>";
> }
> */ // Set the required attendee of the appointment.
> // strHeaderInfo = "<header:to>" + strMailbox +
> "</header:to>";
> strHeaderInfo = "";
> strMailInfo = "<mail:subject>" + strSubject +
> "</mail:subject>";
> //+ "<mail:htmldescription>" + strComments +
> "</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.
>
> // Create the HttpWebRequest object.
> PROPPATCHRequest =
> (System.Net.HttpWebRequest)HttpWebRequest.Create(strConnectionInfo +
> strApptItem);
> // PROPPATCHRequest.Headers.Add("Overwrite", "T");
>
> if (strUserName == null)
> {
> MyCredentialCache =
> (CredentialCache)CredentialCache.DefaultCredentials;
> }
> else
> {
> MyCredentialCache = new System.Net.CredentialCache();
> MyCredentialCache.Add(new System.Uri(strConnectionInfo),
> "NTLM",
> new
> System.Net.NetworkCredential(strUserName, strPassword, strDomain)
> );
>
> // 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();
>
>
> // Set the content type header.
> PROPPATCHRequest.ContentType = "text/xml";
> PROPPATCHRequest.Headers.Set("Overwrite", "t");
> PROPPATCHRequest.Headers.Set("Translate", "f");
> PROPPATCHRequest.Headers.Set("Pragma", "no-cache");
>
> // 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 =
> (System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
>
> // Clean up.
> PROPPATCHResponse.Close();
> if (strRRule != null)
> {
> this.GenerateRecurInstances(RoomID, strConnectionInfo,
> dtStart, dtEnd, strSubject, strLocation, strComments, strRRule, strUserName,
> strPassword, strDomain);
> }
>
> string x = this.FindMeetingUID(strConnectionInfo +
> strApptItem, MyCredentialCache);
> SqlConnection sqlConn = new
> SqlConnection("Server=Roomviewdev.crestron.com;Initial
> Catalog=CrestronRoomView;User ID=sa;Password=S0ftw4re;");
> //SqlConnection sqlConn = new
> SqlConnection("Server=ns1.dstldns.net;Initial Catalog=CrestronRoomView;User
> ID=adam;Password=naomi;");
> SqlCommand sqlCommand = new SqlCommand("CRV_AddNewMeeting",
> sqlConn);
> sqlCommand.CommandType = CommandType.StoredProcedure;
> sqlCommand.Parameters.Add("@GroupwareMeetingID", x);
> sqlCommand.Parameters.Add("@MeetingComment", "");
> sqlCommand.Parameters.Add("@isEditable", 1);
> sqlCommand.Parameters.Add("@RoomViewMeetingID",
> System.Guid.NewGuid().ToString());
> sqlConn.Open();
> sqlCommand.ExecuteNonQuery();
>
>
>
> }
> catch (Exception ex)
> {
> Debug.WriteLine(ex.Message);
> }
> }
> }
date: Thu, 19 Jan 2006 17:40:12 +0100
author: Michael
|
|