Example #1
0
        private void mXML2RTF_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Conver a xml to rtf file");
            string sourceFileName = null;
            string descFileName   = null;

            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter          = "*.xml|*.xml";
                dlg.CheckFileExists = true;
                dlg.ShowReadOnly    = false;
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    sourceFileName = dlg.FileName;
                }
                else
                {
                    return;
                }
            }
            using (SaveFileDialog dlg = new SaveFileDialog())
            {
                dlg.Filter          = "RTF文件(*.rtf)|*.rtf";
                dlg.CheckPathExists = true;
                dlg.OverwritePrompt = true;
                if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    descFileName = dlg.FileName;
                }
                else
                {
                    return;
                }
            }

            DomDocument document = new DomDocument();

            document.Load(sourceFileName, FileFormat.XML);
            using (System.Drawing.Graphics g = document.CreateGraphics())
            {
                document.RefreshSize(g);
                document.ExecuteLayout();
                document.RefreshPages();
                document.Save(descFileName, FileFormat.RTF);
            }
            MessageBox.Show(string.Format("success convert xml file'{0}' to rtf file'{1}'", sourceFileName, descFileName));
        }