locked
Problem in CAL file RRS feed

  • Question

  • Hi,

    I am using this code to create a CAL file for the employees' leave. It takes the start date and end date for the leave from my database. For example, I have a case that the start date is 5 June and End date is 7 June... when sending the file by email using MailMessage, I never had any issue but recently with one or two uses they are receiving the dates from 5 Jun to 8 Jun.

    I though it's a PC issues and nothing to do with the file but when I opned the file using notepad the date was 5 to 8.. when I open the same file from the same email (because I am CCed) I am getting 5 to 7.

    What's the issue?

    // create event file;
    if (!Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BlueFile")))
    { Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BlueFile")); }
    
    file_name = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "BlueFile\\Leave-Emp-" + employee_id.ToString() + ".ics");
    
    FileStream file_stream = new FileStream(file_name, FileMode.OpenOrCreate);
    StreamWriter stream_writer = new StreamWriter(file_stream);
    stream_writer.WriteLine("BEGIN:VCALENDAR");
    stream_writer.WriteLine("VERSION:2.0");
    string strStart = dateFrom.DateTime.ToString("yyyyMMdd");
    string strEnd = dateTo.DateTime.AddDays(1).ToString("yyyyMMdd");
    string strSummary = "On Leave - " + employee_name;
    string strDesctiption = "";
    stream_writer.WriteLine("BEGIN:VEVENT");
    stream_writer.WriteLine("SUMMARY:" + strSummary);
    stream_writer.WriteLine("DESCRIPTION:" + strDesctiption);
    stream_writer.WriteLine("DTSTART;VALUE=DATE:" + strStart);
    stream_writer.WriteLine("DTEND;VALUE=DATE:" + strEnd);
    stream_writer.WriteLine("END:VEVENT");
    stream_writer.WriteLine("END:VCALENDAR");
    stream_writer.Close();
    file_stream.Close();

    Thanks,

    Jassim

    Monday, June 20, 2016 9:14 AM

All replies

  • CORRECTION: The date in the file is always showing 8 Jun to all users but the date from the database is 7 June and Outlook Calendar is showing 7 June as well
    Monday, June 20, 2016 9:30 AM
  • Hi Jassim,

    Thank you for your post. According to your code, I saw that you add 1 day to the dateTo. It leads to the date different between database and CAL file.

    string strEnd = dateTo.DateTime.AddDays(1).ToString("yyyyMMdd");
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by DotNet Wang Tuesday, June 21, 2016 2:52 AM
    Tuesday, June 21, 2016 2:52 AM
  • but i I remove the +1 then Microsoft outlook will show less day (6) where it should be (7)
    Tuesday, June 21, 2016 7:51 AM
  • Hi Jassim,

    Thanks for your feedback. Could your provide your code which analysis this CAL file and put it as an attachment of a mail? Maybe the issue related to the time zone of your computer.

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 21, 2016 11:45 AM
  • DTEND is non-inclusive see: (I hope this helps)

    http://tools.ietf.org/html/rfc5545#page-55

    The following is an example of the "VEVENT" calendar component
          used to represent a multi-day event scheduled from June 28th, 2007
          to July 8th, 2007 inclusively.  Note that the "DTEND" property is
          set to July 9th, 2007, since the "DTEND" property specifies the
          non-inclusive end of the event.
    
           BEGIN:VEVENT
           UID:20070423T123432Z-541111@example.com
           DTSTAMP:20070423T123432Z
           DTSTART;VALUE=DATE:20070628
           DTEND;VALUE=DATE:20070709
           SUMMARY:Festival International de Jazz de Montreal
           TRANSP:TRANSPARENT
           END:VEVENT

    Tuesday, June 21, 2016 11:53 AM
  • This is my cal file:

    BEGIN:VCALENDAR
    VERSION:2.0
    BEGIN:VEVENT
    SUMMARY:On Leave - Jillian Marshall
    DESCRIPTION:
    DTSTART;VALUE=DATE:20160605
    DTEND;VALUE=DATE:20160608
    END:VEVENT
    END:VCALENDAR
    

    Tuesday, June 21, 2016 12:17 PM
  • Hi,

    can anyone help please?

    Thanks

    Thursday, June 23, 2016 9:36 AM
  • Hi Jassim,

    Thank you for your feedback. If you remove AddDays(1), what is the content of your cal file? Have you debug your application and check what is value of dateTo object? Could you provide the code of how did you get dateTo object?

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, June 23, 2016 9:37 AM
  • Hi Jassim,

    How about your issue now?

    Is it resolved?

    Best Regards,
    Li Wang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 28, 2016 2:00 AM