Hi everybody,
Is there any way to implement VCalendar using C# in asp.net? I have List of events in datagrid, in which i am showing only dates in the datagrid.when someone click on a row in datagrid, it will display the details for that date's event in tabular format using a javascript function on a same page.I have one hyperlink to add that details in the microsoft outlook. when some one click on that hyperlink, the displayed event will be added to the outlook.I am very confuse with this as I am implementing first time.
If any body can help me with some code, it will be great for me.
Thank you very much.
Robin
Loading
DhruvilPosted Jul 13, 2006, 8:40 AM
Thanks for your help.
I implement the ical as you suggested. It works good.The only thing I need to ask is, do we have any specific field for appointment time only? Like, I have date and time as different parameters on client side. I am passing them in hidden field to the server. But when I set the date of the appointment in ical, its not seting the time and viceversa. I tried to concatenate the date and time, but date format not allowed concatenation in c#.
any clue?
Thank you very much Dipen.
Dhruvil
Dipen LamaPosted Jul 12, 2006, 8:17 AM
Here is description of some of the iCalendar tags.
BEGIN:VCALENDAR
this line signifies the start of the calendar
VERSION:2.0
this is the icalendar spec version
PRODID:-//ellie//my calendar//lala
this can be any unique product id string
CALSCALE:GREGORIAN
this is the calendar scale, you probably don't want to try anything other than GREGORIAN
BEGIN:VTODO
this begins the to do item
DTSTART;TZID=US/Eastern:20040528T000000
DTSTART is the starting date/time tag. TZID=US/Eastern identifies the time-zone, the date and time combination is of the format YYYYMMDD 'T' HHMMSS (24-hour time format). this tag is required, but isn't important for a to do item. just pad it out with the due date in the format YYMMDD, followed by a T, followed by 000000 (for no time)
SUMMARY:grade quizzes and m1
this is the description of the to do item
UID:2
this is a unique identifier - must be a string that is guarranteed unique for every item in the calendar. i've used simple numbers that count each todo item or event that's added to the calendar.
SEQUENCE:0
this is a number that keeps track of changes made to the item. upon creation, its set to 0, and should be incremented for every change in the starting time/date, the ending time/date, or the due date.
DTSTAMP:20040606T183700
this is the creation date/time of the item
PRIORITY:1
this is the priority of the event, an integer 0-9 where 0 is no priority, 1 is highest, and 9 is lowest.
DUE;VALUE=DATE:20040528T000000
the due date of the to to item
END:VTODO
signifies the end of the to do item
BEGIN:VEVENT
this begins the event
DTSTART;TZID=US/Eastern:20040525T084500
DTSTART is the starting date/time tag. TZID=US/Eastern identifies the time-zone, the date and time combination is of the format YYYYMMDD 'T' HHMMSS (24-hour time format). a time of 000000 indicates an event with no time (all day) and if this is the case, there is no need for a DTEND tag.
DTEND;TZID=US/Eastern:20040525T094500
the ending date/time
SUMMARY:office hours
the description
UID:3
same as to do item, unique identifier
SEQUENCE:3
same as to do item: this is a number that keeps track of changes made to the item. upon creation, its set to 0, and should be incremented for every change in the starting time/date, the ending time/date, or the due date.
DTSTAMP:20040606T183700
this is the creation date/time of the item
END:VEVENT
this signals the end of the event
END:VCALENDAR
this signifies the end of the calendar, should be followed by a cr/lf and then the end of file.
After you have create the iCalendar string format you can now send it to the browser in this way:
string
icalendar = GetICalendarString();Response.Clear();
Response.ContentType =
"text/x-vCalendar";Response.AppendHeader(
"Content-Disposition", "attachment; filename=event" + ".ics");Response.Write(icalendar);
Response.End();
--------------------------------------------------------------------------------------------
Repy to Dhruvil last question. How to add appointment time in iCalendar file?
In the DTSTART tag you have to append both the date and time in this format YYYYMMDD 'T' HHMMSS. Here is some line of code that will help you.
//EventDateTime is of type DateTime
dtStart = EventDateTime.ToString("yyyy") + EventDateTime.ToString("MM") + EventDateTime.ToString("dd") + "T" + Event DateTime.ToString("HH") + EventDateTime.ToString("mm") + "00";string
// if you have time in different variable then append it in the same format as ...+ EventDateTime.ToString("dd") + "T" + YourTimeHour + YourTimeMinute + "00"
//Also have you been able to get the timeOffSet and TimeZoneName
timeSpan = TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);TimeSpan
string timeOffSet = timeSpan.Hours.ToString("00") + timeSpan.Minutes.ToString("00");
string TimeZoneName = TimeZone.CurrentTimeZone.StandardName;
.......
.......
StringWriter
objStringWriter = new StringWriter();objStringWriter.WriteLine(
"BEGIN:VCALENDAR");...
...
objStringWriter.WriteLine(
"DTSTART;TZID=\"" + TimeZoneName + "\":" + dtStart);....
...
string strVcalendar = objStringWriter.ToString();
....
I think with this you can go ahead.
Let me know if you need further help