Hardi
asked on
WebDav & Exchange: Create appointment, avoid overwrite existing one
I can create calendar appointments on an Exchange server using WebDav.
Normally I would set the appointment filename to be subject+".eml"
But if there are 2 appointments with the same subjects they would overwrite each other.
Anyone know the solution?
I am thinking perhaps I should check if http://blah/exchange/blah/Calendar/blah.eml already exists, but I don't know how to do that.
I am using VS 2005, C#, class library.
Normally I would set the appointment filename to be subject+".eml"
But if there are 2 appointments with the same subjects they would overwrite each other.
Anyone know the solution?
I am thinking perhaps I should check if http://blah/exchange/blah/Calendar/blah.eml already exists, but I don't know how to do that.
I am using VS 2005, C#, class library.
ASKER
Thanks LeeDerbyshire
I thought of that too.. but I just want to keep having subjects as filenames, just as Exchange does.
It is also easier to find the item in Exchange Explorer.
Do you know how to check if that URL already exists?
I thought of that too.. but I just want to keep having subjects as filenames, just as Exchange does.
It is also easier to find the item in Exchange Explorer.
Do you know how to check if that URL already exists?
Do a GET to the URL. If you get a 404 response, then it doesn't exist. A 200 means OK, and it does exist. If it exists, then add something unique to the end.
ASKER
Sounds good :-D
How exactly do I "do a GET"?
How exactly do I "do a GET"?
Well, to create the appointments, I guess you are using a WinHTTPRequest object, or something similar, to send a PROPPATCH request? To see if something exists, try sending a GET instead, and look at the status of the response. Maybe you could show the code you are using to create the appointments?
ASKER
Actually I don't understand my code at all... I couldn't find any tutorial about webdav
PROPPATCHRequest = (System.Net.HttpWebRequest )HttpWebRe quest.Crea te(
strCalendarUri + strApptItem); // this is the URL http://....eml
PROPPATCHRequest.Credentia ls = MyCredentialCache;
PROPPATCHRequest.Method = "PROPPATCH";
bytes = Encoding.UTF8.GetBytes((st ring)strAp ptRequest) ; // strApptRequest is the xml
PROPPATCHRequest.ContentLe ngth = bytes.Length;
PROPPATCHRequestStream = PROPPATCHRequest.GetReques tStream();
PROPPATCHRequestStream.Wri te(bytes, 0, bytes.Length);
PROPPATCHRequestStream.Clo se();
PROPPATCHRequest.ContentTy pe = "text/xml";
PROPPATCHResponse = (System.Net.HttpWebRespons e)PROPPATC HRequest.G etResponse (); // Create the appointment in the Calendar folder of the user's mailbox.
PROPPATCHResponse.Close();
Thank you LeeDerbyshire
PROPPATCHRequest = (System.Net.HttpWebRequest
strCalendarUri + strApptItem); // this is the URL http://....eml
PROPPATCHRequest.Credentia
PROPPATCHRequest.Method = "PROPPATCH";
bytes = Encoding.UTF8.GetBytes((st
PROPPATCHRequest.ContentLe
PROPPATCHRequestStream = PROPPATCHRequest.GetReques
PROPPATCHRequestStream.Wri
PROPPATCHRequestStream.Clo
PROPPATCHRequest.ContentTy
PROPPATCHResponse = (System.Net.HttpWebRespons
PROPPATCHResponse.Close();
Thank you LeeDerbyshire
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks LeeDerbyshire it's close. I got it working
try
{
string originalName = strApptItem;
for(int n=1; n<=1000; n++)
{
GETRequest = (System.Net.HttpWebRequest )HttpWebRe quest.Crea te(strCale ndarUri + strApptItem);
GETRequest.Credentials = MyCredentialCache;
GETRequest.Method = "GET";
GETResponse = (System.Net.HttpWebRespons e)GETReque st.GetResp onse();
GETResponse.Close();
strApptItem = originalName + n.ToString();
}
}
catch (Exception ex)
{
if (ex.Message.IndexOf("(404) ") == -1)
throw ex;
}
I don't assume it exists because all subjects are going to contain unique IDs... But just in case... =P
try
{
string originalName = strApptItem;
for(int n=1; n<=1000; n++)
{
GETRequest = (System.Net.HttpWebRequest
GETRequest.Credentials = MyCredentialCache;
GETRequest.Method = "GET";
GETResponse = (System.Net.HttpWebRespons
GETResponse.Close();
strApptItem = originalName + n.ToString();
}
}
catch (Exception ex)
{
if (ex.Message.IndexOf("(404)
throw ex;
}
I don't assume it exists because all subjects are going to contain unique IDs... But just in case... =P
http://server/exchange/user/calendar/20070910-140625-86527.eml