Exemple #1
0
        private void SaveAs_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Rich text format (*.rtf)|*.rtf|Text document (*.txt)|*.txt|HTML document (*.html)|*.html";


            if (ExportAsRTF.IsSelected)
            {
                sfd.FilterIndex = 1;
            }
            else if (ExportAsText.IsSelected)
            {
                sfd.FilterIndex = 2;
            }
            else if (ExportAsHtml.IsSelected)
            {
                sfd.FilterIndex = 3;
            }

            if (sfd.ShowDialog() == true)
            {
                try
                {
                    string extension = System.IO.Path.GetExtension(sfd.FileName).ToLower();
                    if (extension == ".txt")
                    {
                        OpenSave.ExportAsTXT(Document, sfd.FileName);
                    }
                    else
                    if (extension == ".html" || extension == ".htm")
                    {
                        if (!IsExportAsList())
                        {
                            SaveImageFiles(System.IO.Path.GetDirectoryName(sfd.FileName));
                        }
                        OpenSave.ExportAsHtml(Document, __MainWindow, sfd.FileName, IsExportAsList());
                    }
                    else
                    if (extension == ".rtf")
                    {
                        OpenSave.ExportAsRtf(Document, __MainWindow, sfd.FileName, IsExportAsList());
                    }
                    else
                    if (extension == ".xaml")
                    {
                        OpenSave.ExportAsXAML(Document, __MainWindow, sfd.FileName, IsExportAsList());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error while exporting document: " + ex.Message, "Error Exporting Document", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Exemple #2
0
        private void UpdateExportAsHtml()
        {
            string data = "";

            if (IsExportAsList() == false)
            {
                if (__DocumentAsHtml == null)
                {
                    __DocumentAsHtml = OpenSave.ExportAsHtml(Document, __MainWindow);
                }

                data = __DocumentAsHtml;
            }
            else if (IsExportAsList() == true)
            {
                if (__DocumentAsHtml_List == null)
                {
                    __DocumentAsHtml_List = OpenSave.ExportAsHtml_List(Document);
                }

                data = __DocumentAsHtml_List;
            }

            var files = SaveImageFiles(System.IO.Path.GetTempPath());

            __FilesToDelete.AddRange(files);

            string tmp      = System.IO.Path.GetTempFileName();
            string tempFile = tmp + ".html";

            __FilesToDelete.Add(tmp);
            __FilesToDelete.Add(tempFile);

            StreamWriter writer = new StreamWriter(tempFile);

            writer.Write(data);
            writer.Close();

            ExportedText.Text = data;

            Browser.Navigate("file:///" + tempFile);
            Browser.Visibility      = Visibility.Visible;
            ExportedText.Visibility = Visibility.Hidden;
            ExportedRtf.Visibility  = Visibility.Hidden;
            PleaseWait.Visibility   = Visibility.Hidden;
        }