C#中,怎么“打开文件”和“保存文件”?加50分
用openfileDialog函数和SaveFileDialog进行打开和保存;帮我举个实例。也可以发给我raofeng466627538.q@qq.com详细一点...
用openfileDialog函数和SaveFileDialog 进行打开和保存;帮我举个实例。也可以发给我
raofeng466627538.q@qq.com详细一点 展开
raofeng466627538.q@qq.com详细一点 展开
2个回答
展开全部
string resultFile = "";
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "D:\\Patch";
openFileDialog1.Filter = "All files (*.*)|*.*|txt files (*.txt)|*.txt";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
resultFile = openFileDialog1.FileName;
string resultFile = "";
SaveFileDialog saveFileDialog1 = new SaveFileDialog ();
saveFileDialog1.Title = "保存";
saveFileDialog1.Filter = "All files (*.*)|*.*|txt files (*.txt)|*.txt";
saveFileDialog1.FilterIndex = 2;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
resultFile =saveFileDialog1.FileName;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "D:\\Patch";
openFileDialog1.Filter = "All files (*.*)|*.*|txt files (*.txt)|*.txt";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
resultFile = openFileDialog1.FileName;
string resultFile = "";
SaveFileDialog saveFileDialog1 = new SaveFileDialog ();
saveFileDialog1.Title = "保存";
saveFileDialog1.Filter = "All files (*.*)|*.*|txt files (*.txt)|*.txt";
saveFileDialog1.FilterIndex = 2;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
resultFile =saveFileDialog1.FileName;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询