openFileDialog与saveFileDialog的使用

private void btnOpen_Click(object sender, EventArgs e)

        {

            if (openFileDialog1.ShowDialog() == DialogResult.OK)

            {

                string fileName = openFileDialog1.FileName;

                txtInfo.Clear();

                txtInfo.Text = File.ReadAllText(fileName);

            }

        }



        private void btnSave_Click(object sender, EventArgs e)

        {

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)

            {

                string fileName = saveFileDialog1.FileName;

                File.WriteAllText(fileName, txtInfo.Text);

            }

        }

 

你可能感兴趣的:(dialog)