Generating iCalender file using ASP.NET

iCalender is something like an open format text file to add items to the calendar (like Outlook calendar).  It is simply a text file which contains fields and information about the particular event of a calendar.  Once you double click on the iCalendar file, the respective event gets registered in Outlook calendar (of course, with your approval for the event!).
 
Following is the ASP.NET code, which generates iCalendar file dynamically (on the fly) and pushes the same to user.  The user can either directly open it into Outlook or simply save the iCalendar file.
 

Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim sb As New StringBuilder(215)

        sb.AppendFormat("BEGIN:VCALENDAR{0}", Environment.NewLine)

        sb.AppendFormat("CALSCALE:GREGORIAN{0}", Environment.NewLine)

        sb.AppendFormat("VERSION:1.0{0}", Environment.NewLine)

        sb.AppendFormat("BEGIN:VEVENT{0}", Environment.NewLine)

        sb.AppendFormat("DTSTART:20080703T093000{0}", Environment.NewLine)

        sb.AppendFormat("DTEND:20080703T113000{0}", Environment.NewLine)

        sb.AppendFormat("LOCATION:testing some location{0}", Environment.NewLine)

        sb.AppendFormat("SUMMARY:Testing Some subject{0}", Environment.NewLine)

        sb.AppendFormat("CLASS:PUBLIC{0}", Environment.NewLine)

        sb.AppendFormat("END:VEVENT{0}", Environment.NewLine)

        sb.AppendFormat("END:VCALENDAR{0}", Environment.NewLine)

 

        Dim enc As New UTF8Encoding

        Dim arrBytData() As Byte = enc.GetBytes(sb.ToString)

 

        Response.Clear()

        Response.ContentType = "text/plain"

        Response.AppendHeader("Content-Disposition", "attachment; filename=vCalendar.ics")

       Response.AppendHeader("Content-Length", arrBytData.Length.ToString())

        Response.ContentType = "application/octet-stream"

        Response.BinaryWrite(arrBytData)

        Response.Flush()

        Response.End()

    End Sub

End Class

转载于:https://www.cnblogs.com/javafun/archive/2009/02/10/1387380.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值