iCal export

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    iCal export

    Hi im using this code to export appointments from a scheduler to outlook iCal file.

    The date doesnt pull through correctly




    Code:
     
     Private Function GetAsTwoDigit(ByVal val As String) As String
    
            If val.Length = 1 Then
                Return "0" & val
            Else
                Return val
            End If
    
        End Function
    
    
           Dim sb As New StringBuilder()
            sb.AppendLine("BEGIN:  VCALENDAR")
            sb.AppendLine("BEGIN:  VEVENT")
    
            Dim date_start As Date = txtLocation.Text
            Dim date_timeStart As Date = txtLocation.Text
    
            sb.AppendLine(String.Format("DTSTART:{0}{1}{2}T{3}{4}00Z", Year(date_start).ToString, GetAsTwoDigit(Month(date_start).ToString), GetAsTwoDigit(Day(date_start).ToString), GetAsTwoDigit(Hour(date_start).ToString), GetAsTwoDigit(Minute(date_start).ToString)))
    
            Dim date_end As Date = txtLocation.Text
            Dim date_timeEnd As Date = txtLocation.Text
            sb.AppendLine(String.Format("DTEND:{0}{1}{2}T{3}{4}00Z", Year(date_end).ToString, GetAsTwoDigit(Month(date_end).ToString), GetAsTwoDigit(Day(date_end).ToString), GetAsTwoDigit(Hour(date_end).ToString), GetAsTwoDigit(Minute(date_end).ToString)))
            MsgBox(sb.ToString)
    
            sb.AppendLine(String.Format("LOCATION;ENCODING=QUOTED-PRINTABLE:{0}", txtLocation.Text))
            sb.AppendLine("UID:    FD7D9F229CAE422AA76738B77044DA9659A83")
            sb.AppendLine(String.Format("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:{0}", txtDescription.Text))
            sb.AppendLine(String.Format("SUMMARY;ENCODING=QUOTED-PRINTABLE:{0}", txtSummary.Text))
            sb.AppendLine(String.Format("PRIORITY:{0}", txtPriority.Text))
            sb.AppendLine("End : VEVENT")
            sb.AppendLine("End : VCALENDAR")
            Return sb.ToString
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You aren't properly creating a Date.
    You can't have:

    Dim myDate As DateTime = "someString "

    Try using the DateTime.Parse( ) method or the DateTime.TryPar se method to try to parse the date supplied into a proper DateTime structure.

    (PS I recommend you use a DateTime structure over a Date structure.)

    -Frinny

    Comment

    • OuTCasT
      Contributor
      • Jan 2008
      • 374

      #3
      Hi Frinny

      Sorry man, I was just testing the date in that txtLocation textbox.
      I retrieve the date from a gridview and then assign it to a variable which replaces the txtLocation.

      When i read the string back everything seems to be right.

      BEGIN: VCALENDAR BEGIN: VEVENT
      DTSTART:2009112 7T9000Z
      DTEND:20091127T 9000Z
      LOCATION;ENCODI NG=QUOTED-PRINTABLE:2009-11-27 09:00:00 AM UID: FD7D9F229CAE422 AA76738B77044DA 9659A83 DESCRIPTION;ENC ODING=QUOTED-PRINTABLE:New Appointment SUMMARY;ENCODIN G=QUOTED-PRINTABLE:New Summary Appointment PRIORITY:HIGH End : VEVENT End :
      VCALENDAR

      The date is correct in the DTStart but wen the iCal file opens its irregular but i will check to see what i can do about it

      Comment

      Working...