VRBO ical import from ASP.Net icalHandler

Posted by keith Filed Under Property Management
My clients wanted to import their availability calendars to VRBO so they did not have to manually sync them. I looked into several code solutions to allow my Property Management customers to export their calendars from my ASP.net property management platform to .ical format. Here is my version for icalHandler.ashx. There is no web.config changes needed.

<%@ WebHandler Language="C#" Class="icalHandler" %>
using System;
using System.Web;

public class icalHandler : IHttpHandler {
  
  public bool IsReusable
  {
    get
    {
      return true;
    }
  }

  string DateFormat
  {
    get
    {
      return "yyyyMMddTHHmmssZ"; // 20060215T092000Z
    }
  }

  public void ProcessRequest(HttpContext context)
  {
    string listingId = context.Request.QueryString["ListingId"];
    Listing listing = Listing.GetListing(new Guid(listingId));

    context.Response.ContentType = "text/calendar";
    context.Response.AddHeader("Content-disposition", "attachment; filename=Listing" + listing.ListingRowId + ".ics");
    context.Response.Write("BEGIN:VCALENDAR");
    context.Response.Write("\nVERSION:2.0");
    context.Response.Write("\nMETHOD:PUBLISH");
    
    foreach (Availability avail in listing.Availabilities)
    {
      DateTime startDate = avail.StartDate;
      DateTime endDate = avail.EndDate;

      if (startDate > DateTime.Now || endDate > DateTime.Now)
      {
        context.Response.Write("\nBEGIN:VEVENT");
        context.Response.Write("\nORGANIZER:MAILTO:" + "info@nationalrentalpros.com");
        context.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat));
        context.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat));
        context.Response.Write("\nLOCATION:" + listing.Title);
        context.Response.Write("\nUID:" + DateTime.Now.ToUniversalTime().ToString(DateFormat) + "@enkode.io");
        context.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat));
        context.Response.Write("\nSUMMARY:" + "Not Available");
        context.Response.Write("\nDESCRIPTION:" + "Reserved");
        context.Response.Write("\nPRIORITY:5");
        context.Response.Write("\nCLASS:PUBLIC");
        context.Response.Write("\nEND:VEVENT");
      }
    }
    context.Response.Write("\nEND:VCALENDAR");
    context.Response.End();
  }

}

Add comment


  • Comment
  • Preview

Comment
Loading

Enkode offers development services for cloud-enabled software-as-a-service (SaaS). We can help you take your application from ideas to life. Create apps for employees and customers to drive business.
5450 E. Deer Valley Dr. #3004
Phoenix
Arizona
85054
United States