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.
LVL 6
HardiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LeeDerbyshireCommented:
The destination URL doesn't need to be based on the subject, Exchange just does that by default, and adds incrementing numbers to the end if required.  The easiest thing to do is to create a unique URL based on the date and time, and then add a random number on the end.  You will end up with something like

http://server/exchange/user/calendar/20070910-140625-86527.eml
0
HardiAuthor Commented:
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?
0
LeeDerbyshireCommented:
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.
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

HardiAuthor Commented:
Sounds good :-D
How exactly do I "do a GET"?
0
LeeDerbyshireCommented:
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?
0
HardiAuthor Commented:
Actually I don't understand my code at all... I couldn't find any tutorial about webdav

                PROPPATCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(
                    strCalendarUri + strApptItem); // this is the URL http://....eml
                PROPPATCHRequest.Credentials = MyCredentialCache;
                PROPPATCHRequest.Method = "PROPPATCH";
                bytes = Encoding.UTF8.GetBytes((string)strApptRequest); // strApptRequest is the xml
                PROPPATCHRequest.ContentLength = bytes.Length;
                PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream();
                PROPPATCHRequestStream.Write(bytes, 0, bytes.Length);
                PROPPATCHRequestStream.Close();
                PROPPATCHRequest.ContentType = "text/xml";
                PROPPATCHResponse = (System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse(); // Create the appointment in the Calendar folder of the user's mailbox.
                PROPPATCHResponse.Close();

Thank you LeeDerbyshire
0
LeeDerbyshireCommented:
Well, I have to admit that I don't know much about C# - I saw this question in the Exchange admin area, and thought I'd answer it because I do some coding, too.  But I only really use VB.  At a guess, I'd say you'd need something like this:

GETRequest = (System.Net.HttpWebRequest)
  HttpWebRequest.Create(strCalendarUri + strApptItem);
GETRequest.Credentials = MyCredentialCache;
GETRequest.Method = "GET";
GETResponse = (System.Net.HttpWebResponse)
  GETRequest.GetResponse();
If GETRequest.StatusCode = "404"
  (// Use your code to add the appointment )
GETResponse.Close();

To be honest, I think it would be easier to always assume that it exists, and to use the subject and add some random characters based on the date/time etc. as described above.

http://server/exchange/users/calendar/TestAppointment-20070911-132855-85634.eml
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HardiAuthor Commented:
Thanks LeeDerbyshire it's close. I got it working

                try
                {
                    string originalName = strApptItem;
                    for(int n=1; n<=1000; n++)
                    {
                        GETRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strCalendarUri + strApptItem);
                        GETRequest.Credentials = MyCredentialCache;
                        GETRequest.Method = "GET";
                        GETResponse = (System.Net.HttpWebResponse)GETRequest.GetResponse();
                        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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.