예제 #1
0
        /// <summary>
        /// Download the calendar file
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        protected void btnDownload_Click(object sender, EventArgs e)
        {
            VCalendar vc = (VCalendar)Session["VCalendar"];

            // Send the file to the user
            this.Response.ClearContent();

            if (vc.Version == SpecificationVersions.vCalendar10)
            {
                this.Response.ContentType = "text/x-vcalendar";
                this.Response.AppendHeader("Content-Disposition", "inline;filename=Calendar.vcs");
            }
            else
            {
                this.Response.ContentType = "text/calendar";
                this.Response.AppendHeader("Content-Disposition", "inline;filename=Calendar.ics");
            }

            // This is only applicable for vCalendar 1.0
            switch (cboPropEncoding.SelectedIndex)
            {
            case 0:
                BaseProperty.DefaultEncoding = new UTF8Encoding(false, false);
                break;

            case 1:
                BaseProperty.DefaultEncoding = Encoding.GetEncoding("iso-8859-1");
                break;

            default:
                BaseProperty.DefaultEncoding = new ASCIIEncoding();
                break;
            }

            // The collection can be written directly to the stream.  Note that more likely than not, it will be
            // written as UTF-8 encoded data.
            vc.WriteToStream(Response.Output);
            Response.End();
        }
예제 #2
0
        /// <summary>
        /// Save a calendar file
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event arguments</param>
        private void miSave_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Title  = "Save Calendar File";
                dlg.Filter = "ICS files (*.ics)|*.ics|VCS files (*.vcs)|*.vcs|All files (*.*)|*.*";

                if (vCal.Version == SpecificationVersions.vCalendar10)
                {
                    dlg.DefaultExt  = "vcs";
                    dlg.FilterIndex = 2;
                }
                else
                {
                    dlg.DefaultExt  = "ics";
                    dlg.FilterIndex = 1;
                }

                dlg.InitialDirectory = Path.GetFullPath(Path.Combine(
                                                            Environment.CurrentDirectory, @"..\..\..\..\..\PDIFiles"));
                dlg.FileName = lblFilename.Text;

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        this.Cursor = Cursors.WaitCursor;

                        // Open the file and write the calendar to it. We'll use the same encoding method used by
                        // the parser.
                        using (var sw = new StreamWriter(dlg.FileName, false, PDIParser.DefaultEncoding))
                        {
                            vCal.WriteToStream(sw);
                        }

                        wasModified      = false;
                        lblFilename.Text = dlg.FileName;
                    }
                    catch (Exception ex)
                    {
                        string error = String.Format("Unable to save calendar:\n{0}", ex.Message);

                        if (ex.InnerException != null)
                        {
                            error += ex.InnerException.Message + "\n";

                            if (ex.InnerException.InnerException != null)
                            {
                                error += ex.InnerException.InnerException.Message;
                            }
                        }

                        System.Diagnostics.Debug.Write(ex);

                        MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        this.Cursor = Cursors.Default;
                    }
                }
            }
        }