Aggiungere un appuntamento in calendario con ASP.NET

di Daniele Bochicchio, in ASP.NET, C#,

Il formato utilizzato da molti programmi per lo scambio di appuntamenti è noto come vCalendar e si basa su un semplice file di testo, formatto a dovere.
In questo esempio generiamo un appuntamento impostando in maniera manuale le informazioni:

<SCRIPT RUNAT="SERVER" LANGUAGE="C#">

// funzione per generare l'appuntamento
void Appointment(DateTime startDate, DateTime endDate, string subject, string location, string description)
{
  // le date devono essere GMT
  int GMT = 1;
  startDate = startDate.AddHours(-GMT);
  endDate = endDate.AddHours(-GMT);

  // generazione del content Type
  Response.ContentType = "text/x-vcalendar";
  Response.AddHeader("content-disposition", "inline; filename=" + location + ".vcs;");

  // corpo dell'appuntamento
  Response.Write("BEGIN:VCALENDAR\r\n");
  Response.Write("VERSION:1.0\r\n");
  Response.Write("BEGIN: VEVENT\r\n");
  Response.Write("DTStart:" + startDate.ToString("yyyyMMddTHHmmssZ") + "\r\n");
  Response.Write("DTEnd:" + endDate.ToString("yyyyMMddTHHmmssZ") + "\r\n");
  Response.Write("LOCATION;ENCODING=QUOTED-PRINTABLE:" + location  + "\r\n");
  Response.Write("SUMMARY;ENCODING=QUOTED-PRINTABLE:" + description  + "\r\n");
  Response.Write("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + subject  + "\r\n");
  Response.Write("UID:" + startDate.ToString("yyyyMMddTHHmmssZ") + endDate.ToString("yyyyMMddTHHmmssZ") + "\r\n");
  Response.Write("PRIORITY:3\r\n");
  Response.Write("End:VEVENT\r\n");
  Response.Write("End:VCALENDAR\r\n");

}

void Page_Load()
{
  // sostituire con dati prelevati da un database
  Appointment(DateTime.Now, DateTime.Now.AddMinutes(5), "Descrizione", "Location", "Corpo esteso dell'appuntamento");
}

</SCRIPT>

Per estendere al meglio l'esempio è consigliabile creare un HttpHandler che provveda a prelevare direttamente i dati da un database.

Commenti

Visualizza/aggiungi commenti

| Condividi su: Twitter, Facebook, LinkedIn

Per inserire un commento, devi avere un account.

Fai il login e torna a questa pagina, oppure registrati alla nostra community.

Approfondimenti

I più letti di oggi