In this post I will walk you through the steps of reading calendar events from CALDAV supported servers. Yahoo, Google, etc. supports CALDAV
What is CALDAV?
CALDAV is an internet standard allowing client to access scheduling information on remote server. It’s an extension of WebDAV which is a HTTP-based protocol for data manipulation. The protocol is defined by RFC 4791. As it’s an extension to WEBDAV protocol it uses HTTP verbs to manipulate calendar events some of them mostly used are PROPFIND, SEARCH, etc.
- Every server has a separate URI to access calendar events.
- Each Calendar folder is a collection and contains many calendar events. Each calendar event is a file and ended with .ics extension. .ics is well understood by many clients and you can easily export data from .ics to local client application.
How to Program
Now let’s see how to write a code to call Yahoo calendar events
- First of all create a new project in Microsoft Visual C# .NET
- Add reference to DDay.iCal library from Nuget Package manager console. This library will be used to read .ics files and read information about each event.
Write below code to retrieve calendar event on any click event.
In the above code snippet you have to configure your user name, password and modify the calendar URI depending on your calendarname and username.
If you see the code, I specified a content string which contains the request that I am sending it to the server. CALDAV have specific request formats which you can study here
ExecuteMethod is a helper method that sends request to the server and returns the response stream. Once I get the response stream I load the XML document and read the InnerXml of the file to get the complete XML. Then I parse the xml document and search for DAV:href element that contains the calendar event file (.ics) information. Once I get the list of .ics file paths, I call DownloadICS helper method to get the complete event information.
Following are the helper method that performs specific operations. Please write these in your code to compile the project.
DownloadICS – Downloads .ics files
ExecuteMethod: Request calendar and returns response stream