Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:00:17+00:00 2026-06-05T18:00:17+00:00

I’m trying to create a .vcs file in C#. Basically in outlook if you

  • 0

I’m trying to create a .vcs file in C#. Basically in outlook if you add a calendar appointment it creates a file that in outlook looks like this:

enter image description here

You can actually export this file, right click on it and open it up in your favorite text editor. It looks something like this:

BEGIN:VCALENDAR
PRODID:-//Flo Inc.//FloSoft//EN
BEGIN:VEVENT
DTSTART:6/12/2012 12:00:00 PM
DTEND:6/12/2012 1:00:00 PM
LOCATION:Meeting room 1
DESCRIPTION;ENCODING=QUOTED-PRINTABLE:Learn about assets.
SUMMARY:asset management training.
X-MICROSOFT-CDO-BUSYSTATUS:OOF
PRIORITY:5
END:VEVENT
END:VCALENDAR

So what I am having a problem with is the actual time in DTSTART and DTEND from above. You can see that when I open the outlook file it says 11:00am (as the screen shot shows) but in the text file I have it as 12:00pm.

So I have an application (training application) where I dynamically create one of these vcs files. Using C# I gather the subject, location, description and dates (with times) like so:

 protected void btnOutlook_Click(object sender, EventArgs e)
        {
            string location;
            string description;
            string subject;
            string fromTime;
            string toTime;

            location = txtLocation.Text;
            description = txtDescription.Text;
            subject = lblTitle.Text;
            fromTime = ddlFromTimeHH.SelectedItem.Text + ":" + ddlFromTimeMM.SelectedItem.Text + ddlFromTimeAMPM.SelectedItem.Text;
            toTime = ddlToTimeHH.SelectedItem.Text + ":" + ddlToTimeMM.SelectedItem.Text + ddlToTimeAMPM.SelectedItem.Text;

            string begin = lblDate.Text + " " + fromTime;
            string end = lblDate.Text + " " + toTime;
            string format = "dd/MM/yyyy h:mmtt";

            DateTime trainingDateBegin;
            DateTime trainingDateEnd;

            if (DateTime.TryParseExact(begin, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out trainingDateBegin))
            {
                //good date
            }


            if (DateTime.TryParseExact(end, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out trainingDateEnd))
            {
                //good date
            }

            OpenVCSFile("vcsFile.aspx?TrainingDateBegin=" + trainingDateBegin + "&TrainingDateEnd=" + trainingDateEnd + "&Location=" + location + "&Subject=" + subject + "&Description=" + description, "Utilities", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=800,height=500,left=10,top=20");
        }

So in the above code fromTime just becomes for instance 7:00 am and toTime becomes something like 8:00 am. I then use DateTime.TryParseExact to merge the date with the time so it becomes for instance 06/01/2012 7:00 am for beginDate and for endDate it becomes for instance 06/01/2012 8:00 am.

So far so good…then I just call a function OpenVCSFile which is just some javascript to open the passed in url like so:

protected void OpenVCSFile(string url, string name, string att)
        {
            Response.Write("<script language='JavaScript'>");
            Response.Write("x=window.open('" + url + "', '" + name + "','" + att + "');");
            Response.Write("x.focus();");
            Response.Write("</script>");
        }

This then calls the vcsFile.aspx page where I can fill in the outlook values…

protected void Page_Load(object sender, EventArgs e)
        {
            DateTime beginDate;
            DateTime endDate;
            string location;
            string description;
            string subject;

            beginDate = Convert.ToDateTime(Request.QueryString["TrainingDateBegin"]);
            endDate = Convert.ToDateTime(Request.QueryString["TrainingDateEnd"]);

            location = Request.QueryString["Location"];
            description = Request.QueryString["Description"];
            subject = Request.QueryString["Subject"];

            MemoryStream mStream = new MemoryStream();
            StreamWriter writer = new StreamWriter(mStream);

            writer.AutoFlush = true;

            //header
            writer.WriteLine("BEGIN:VCALENDAR");
            writer.WriteLine("PRODID:-//Flo Inc.//FloSoft//EN");
            writer.WriteLine("BEGIN:VEVENT");

            //BODY
            writer.WriteLine("DTSTART:" + beginDate);   //why dont the times come out right...
            writer.WriteLine("DTEND:" + endDate);       //same here
            writer.WriteLine("LOCATION:" + location);
            writer.WriteLine("DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + description);
            writer.WriteLine("SUMMARY:" + subject);
            writer.WriteLine("X-MICROSOFT-CDO-BUSYSTATUS:OOF");

            //FOOTER
            writer.WriteLine("PRIORITY:5");
            writer.WriteLine("END:VEVENT");
            writer.WriteLine("END:VCALENDAR");

            //MAKE IT DOWNLOADABLE
            Response.Clear(); //clears the current output content from the buffer
            Response.AppendHeader("Content-Disposition", "attachment; filename=AddToOutlookCalendar.vcs");
            Response.AppendHeader("Content-Length", mStream.Length.ToString());
            Response.ContentType = "application/download";
            Response.BinaryWrite(mStream.ToArray());
            Response.End();
        }

Everything appears to work EXCEPT the most important part, the section where I do this:

writer.WriteLine("DTSTART:" + beginDate);   //why dont the times come out right...
 writer.WriteLine("DTEND:" + endDate);       //same here

The date comes out right as you see in the outlook screen shot, but the time is always wrong…
Usually outlook will open it up with 10:00 am till 11:00 am. But it never takes the time that I give it. For instance, in my c# code here is the watch screen:

trainingDateBegin {12/6/2012 12:00:00 PM}
trainingDateEnd {12/6/2012 1:00:00 PM}

So my app is passing in the date of 12/6/2012 with a time of 12:00:00 pm till 12/6/2012 1:00:00 pm.
But then when the vcs file is generated here is the result:

enter image description here

(if the image doesnt show up basically outlook is having all the correct information: subject, location, start date end date BUT the time is wrong. It says 11am till 12pm. Its almost like its using my system clock EST)…

Does anyone know what I might be doing wrong. Sorry for the long post:(.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:00:19+00:00Added an answer on June 5, 2026 at 6:00 pm

    I think it’s to do with timezones; you could either add a timezone or (much simpler) use the UTC time in your file.

    If you do add a timezone you’ll need to use vCal version 2, since Outlook doesn’t support timezones in version 1.


    EDIT: This is an example of the syntax taken from the Wikipedia article on VCalendar. This event occurs July 14, 1997 17:00 (UTC) through July 15, 1997 03:59:59 (UTC):

    BEGIN:VCALENDAR
    VERSION:2.0
    PRODID:-//hacksw/handcal//NONSGML v1.0//EN
    BEGIN:VEVENT
    UID:uid1@example.com
    DTSTAMP:19970714T170000Z
    ORGANIZER;CN=John Doe:MAILTO:john.doe@example.com
    DTSTART:19970714T170000Z
    DTEND:19970715T035959Z
    SUMMARY:Bastille Day Party
    END:VEVENT
    END:VCALENDAR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.