Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WebDav & Exchange: Create appointment, avoid overwrite existing one

Posted on 2007-09-10
8
Medium Priority
?
2,938 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:Hardi
  • 4
  • 4
8 Comments
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 19860594
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
 
LVL 6

Author Comment

by:Hardi
ID: 19864991
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
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 19865055
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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
LVL 6

Author Comment

by:Hardi
ID: 19865083
Sounds good :-D
How exactly do I "do a GET"?
0
 
LVL 31

Expert Comment

by:LeeDerbyshire
ID: 19865638
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
 
LVL 6

Author Comment

by:Hardi
ID: 19866024
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
 
LVL 31

Accepted Solution

by:
LeeDerbyshire earned 1200 total points
ID: 19867914
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
 
LVL 6

Author Comment

by:Hardi
ID: 19873351
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
How to effectively resolve the number one email related issue received by helpdesks.
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question