Example #1
0
        // リッチテキストを保存
        private void ButtonSave_Click(System.Object sender, System.EventArgs e)
        {
            // SaveFileDialogクラスのインスタンスを作成
            SaveFileDialog sfd = new SaveFileDialog();

            // はじめのファイル名を指定する
            // はじめに「ファイル名」で表示される文字列を指定する
            sfd.FileName = "新しいファイル.rtf";
            // はじめに表示されるフォルダを指定する
            // 指定しない(空の文字列)の時は、現在のディレクトリが表示される
            // sfd.InitialDirectory = "C:\"
            // [ファイルの種類]に表示される選択肢を指定する
            sfd.Filter = "リッチテキストファイル(*.rtf)|*.rtf|すべてのファイル(*.*)|*.*";
            // [ファイルの種類]ではじめに選択されるものを指定する
            // 2番目の「すべてのファイル」が選択されているようにする
            sfd.FilterIndex = 1;
            // タイトルを設定する
            sfd.Title = "保存先のファイルを選択してください";
            // ダイアログボックスを閉じる前に現在のディレクトリを復元するようにする
            sfd.RestoreDirectory = true;
            // 既に存在するファイル名を指定したとき警告する
            // デフォルトでTrueなので指定する必要はない
            sfd.OverwritePrompt = true;
            // 存在しないパスが指定されたとき警告を表示する
            // デフォルトでTrueなので指定する必要はない
            sfd.CheckPathExists = true;
            // ダイアログを表示する
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                // OKボタンがクリックされたとき、選択されたファイル名を表示する
                Console.WriteLine(sfd.FileName);
                RichTextBox1.SaveFile(sfd.FileName, RichTextBoxStreamType.RichText);
            }
        }
 private void SaveToolStripButton_Click(object sender, EventArgs e)
 {
     try
     {
         if (IsSaved == false)
         {
             if (Saved)
             {
                 RichTextBox1.SaveFile(FileName);
             }
             else
             {
                 SaveFileDialog1.FileName = FileName;
                 if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
                 {
                     FileName = SaveFileDialog1.FileName;
                     RichTextBox1.SaveFile(FileName);
                     IsSaved = true;
                     Saved   = true;
                 }
             }
         }
     }
     catch
     {
         return;
     }
 }
Example #3
0
        private void btnWellFormNess_Click(object sender, EventArgs e)
        {
            try
            {
                lstErrors.Items.Clear();

                RichTextBox1.SaveFile(xmlFileName, RichTextBoxStreamType.PlainText);

                IsWellFormedXml = true;

                using (FileStream stream = File.OpenRead(AppDomain.CurrentDomain.BaseDirectory + "PatentEnhancedPrioritySubstanceIndexing-2.3.xsd"))
                {
                    XmlReaderSettings settings = new XmlReaderSettings();

                    XmlSchema schema = XmlSchema.Read(stream, OnXmlSyntaxError);
                    settings.ValidationType = ValidationType.Schema;
                    settings.Schemas.Add(schema);
                    settings.ValidationEventHandler += OnXmlSyntaxError;

                    string strError = "";
                    using (XmlReader validator = XmlReader.Create(txtXmlFile.Text.Trim(), settings))
                    {
                        try
                        {
                            // Validate the entire xml file
                            while (validator.Read())
                            {
                                lineInf = (IXmlLineInfo)validator;
                            }
                        }
                        catch (Exception ex)
                        {
                            if (lineInf.HasLineInfo())
                            {
                                strError = lineInf.LineNumber.ToString() + ": " + lineInf.LinePosition.ToString() + " " + ex.Message;
                            }
                            lstErrors.Items.Add(strError);
                        }
                    }
                }
                if (IsWellFormedXml)
                {
                    MessageBox.Show("Wellformed XML", "Wellformed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                PepsiLiteErrorHandling.WriteErrorLog(ex.ToString());
            }
        }
Example #4
0
 private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         if (TabControl1.SelectedIndex == 1)
         {
             RichTextBox1.SaveFile(xmlFileName, RichTextBoxStreamType.PlainText);
             webBrowser1.Navigate(xmlFileName);
         }
     }
     catch (Exception ex)
     {
         PepsiLiteErrorHandling.WriteErrorLog(ex.ToString());
     }
 }
Example #5
0
        private void ParseXMLFile()
        {
            try
            {
                if (xmlFileName == null)
                {
                    MessageBox.Show("Please open an XML file for parsing", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                this.Cursor = Cursors.WaitCursor;

                string strXSDPath = AppDomain.CurrentDomain.BaseDirectory + "PatentEnhancedPrioritySubstanceIndexing-2.3.xsd";

                RichTextBox1.SaveFile(xmlFileName, RichTextBoxStreamType.PlainText);

                XmlTextReader       xmlTxtReader = new XmlTextReader(xmlFileName);
                XmlValidatingReader xmlValReader = new XmlValidatingReader(xmlTxtReader);
                xmlValReader.ValidationType = ValidationType.Schema;
                xmlValReader.Schemas.Add(null, strXSDPath);
                strError = "";
                lstErrors.Items.Clear();

                xmlValReader.ValidationEventHandler += WriteErrorLog;

                IsValidXmlFile = true;
                do
                {
                    try
                    {
                        if (xmlValReader.Read())
                        {
                            lineInf = (IXmlLineInfo)xmlValReader;
                        }
                    }
                    catch (Exception exx)
                    {
                        try
                        {
                            IsValidXmlFile = false;

                            if (lineInf.HasLineInfo())
                            {
                                strError = lineInf.LineNumber.ToString() + ": " + lineInf.LinePosition.ToString() + " " + exx.Message;
                            }

                            if (exx.Message.IndexOf("EndElement") > 1)
                            {
                                break;
                            }
                            lstErrors.Items.Add(strError);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Some unexpected error occurred \r\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            break;
                        }
                    }
                }while (!xmlTxtReader.EOF);

                xmlValReader.Close();
                xmlTxtReader.Close();

                Cursor = Cursors.Default;

                if (IsValidXmlFile == false)
                {
                    MessageBox.Show("File is not valid", "Invalid XML File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("File is validated with XSD successfully", "Valid XML File", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                PepsiLiteErrorHandling.WriteErrorLog(ex.ToString());
            }
        }