using System; using System.IO; using System.Windows.Forms; namespace TestApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void openToolStripMenuItem_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { } private void openToolStripMenuItem_Click_1(object sender, EventArgs e) { var fileContent = string.Empty; var filePath = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "XML-File | *.xml|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file filePath = openFileDialog.FileName; //Read the contents of the file into a stream var fileStream = openFileDialog.OpenFile(); using (StreamReader reader = new StreamReader(fileStream)) { fileContent = reader.ReadToEnd(); } } } //MessageBox.Show(fileContent, "File Content at path: " + filePath, MessageBoxButtons.OK); } private void saveToolStripMenuItem_Click(object sender, EventArgs e) { Stream myStream; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "XML-File | *.xml|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 2; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { if ((myStream = saveFileDialog1.OpenFile()) != null) { // Code to write the stream goes here. myStream.Close(); } } } /*private void validateUserEntry() { // Checks the value of the text. if (textBox1.Text.Length == 0 && textBox2.Text.Length == 0 && textBox3.Text.Length == 0) { // Initializes the variables to pass to the MessageBox.Show method. string message = " AAAAAAAAAAAAA"; string caption = "Error Detected in Input"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result; // Displays the MessageBox. result = MessageBox.Show(message, caption, buttons); if (result == System.Windows.Forms.DialogResult.Yes) { // Closes the parent form. this.Close(); } } }*/ } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)