jvilalta.CalDAV 2.0.0

dotnet add package jvilalta.CalDAV --version 2.0.0
                    
NuGet\Install-Package jvilalta.CalDAV -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="jvilalta.CalDAV" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="jvilalta.CalDAV" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="jvilalta.CalDAV" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add jvilalta.CalDAV --version 2.0.0
                    
#r "nuget: jvilalta.CalDAV, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package jvilalta.CalDAV@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=jvilalta.CalDAV&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=jvilalta.CalDAV&version=2.0.0
                    
Install as a Cake Tool

CalDAV Client for C#

A .NET 9 CalDAV client library that allows you to connect to CalDAV servers using a username, password, and server URL.

Features

  • Connection Management: Connect to CalDAV servers with username/password authentication
  • Calendar Discovery: Automatically discover available calendars
  • Event Management: Create, read, update, and delete calendar events
  • iCalendar Support: Full support for iCalendar (RFC 5545) format
  • Async/Await: Modern async programming patterns throughout

Usage

Basic Setup

using CalDAV;

// Create a CalDAV client
var client = new CalDAVClient("https://your-server.com/caldav/", "username", "password");

// Test the connection
var isConnected = await client.TestConnectionAsync();
if (isConnected)
{
    Console.WriteLine("Connected successfully!");
}

// Initialize the client (discovers endpoints)
await client.InitializeAsync();

Working with Calendars

// Get list of available calendars
var calendars = await client.GetCalendarsAsync();

foreach (var calendar in calendars)
{
    Console.WriteLine($"Calendar: {calendar.DisplayName}");
    Console.WriteLine($"URL: {calendar.Url}");
    Console.WriteLine($"Description: {calendar.Description}");
}

Working with Events

// Get events from a calendar
var events = await client.GetEventsAsync(calendar.Url);

// Get events within a date range
var startDate = DateTime.Today;
var endDate = DateTime.Today.AddDays(30);
var filteredEvents = await client.GetEventsAsync(calendar.Url, startDate, endDate);

// Create a new event
var eventData = ICalendarGenerator.CreateSimpleEvent(
    "Meeting with Team",
    DateTime.Now.AddDays(1),
    DateTime.Now.AddDays(1).AddHours(1),
    "Weekly team meeting",
    "Conference Room A"
);

var eventUrl = await client.CreateEventAsync(calendar.Url, eventData);

// Update an existing event
await client.UpdateEventAsync(eventUrl, updatedEventData, etag);

// Delete an event
await client.DeleteEventAsync(eventUrl, etag);

Creating Custom Events

using CalDAV.Models;
using CalDAV.Utils;

// Create a custom event
var customEvent = new CalendarEvent
{
    Uid = Guid.NewGuid().ToString(),
    Summary = "Custom Event",
    Description = "This is a custom event",
    StartTime = DateTime.Now.AddDays(2),
    EndTime = DateTime.Now.AddDays(2).AddHours(2),
    Location = "Meeting Room B",
    Organizer = "mailto:organizer@example.com",
    Attendees = new List<string> 
    { 
        "mailto:attendee1@example.com", 
        "mailto:attendee2@example.com" 
    }
};

var iCalData = ICalendarGenerator.GenerateEvent(customEvent);
await client.CreateEventAsync(calendar.Url, iCalData);

Supported CalDAV Servers

This client has been designed to work with standard CalDAV servers including:

  • Apple Calendar Server
  • Google Calendar (via CalDAV API)
  • Microsoft Exchange (with CalDAV support)
  • Nextcloud/ownCloud
  • Radicale
  • Baikal
  • Zimbra

Error Handling

try
{
    var calendars = await client.GetCalendarsAsync();
    // Process calendars...
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"Network error: {ex.Message}");
}
catch (InvalidOperationException ex)
{
    Console.WriteLine($"Client not initialized: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"General error: {ex.Message}");
}

Authentication

Currently supports HTTP Basic Authentication. For servers requiring other authentication methods, you may need to extend the client or handle authentication externally.

Dependencies

  • .NET 9.0
  • System.Net.Http (built-in)
  • System.Xml (built-in)

Example Application

Run the included example application:

dotnet run

The example demonstrates:

  • Connecting to a CalDAV server
  • Discovering calendars
  • Fetching events
  • Creating new events

Configuration

Update the server URL, username, and password in Program.cs or modify the code to accept them as command-line arguments or environment variables.

License

This project is provided as-is for educational and development purposes.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 71 8/16/2025
1.0.0 68 8/15/2025

Initial release of CalDAV Client for .NET 9. Features include calendar discovery, event management, and iCalendar support.