/// <summary> /// Load selected xml file in a text box /// </summary> private void btnSelecXmlFile_Click(object sender, EventArgs e) { var fileContent = string.Empty; var filePath = string.Empty; try { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "All files (*.*)|*.*|xml files (*.xml)|*.xml"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { // Check if the user has selected a xml file string extension = new FileInfo(openFileDialog.FileName).Extension.ToLower(); if (extension != ".xml") { throw new Exception("You need to select an xml file"); } // Get the path of specified file filePath = openFileDialog.FileName; this.Text = filePath; // Read the contents of the file into stream var fileStream = openFileDialog.OpenFile(); // Load the XML stream in a textbox UFile uFile = new UFile(); UXmlReader xmlReader = new UXmlReader(fileStream, chkDecode.Checked); fileContent = uFile.GetFileContent(xmlReader); txtFileContent.Text = fileContent; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }