楼主既然保存文件, 就要把保存文件对话框显示出来, 即使你已经有了保存路径了, 下面引用 msdn 的代码说明: SaveFileDialog1.CreatePrompt = true; // 文件不存在是是否提示新建 SaveFileDialog1.OverwritePrompt = true; // 文件存在是是否提示覆盖 // Set the file name to myText.txt, set the type filter // to text files, and set the initial directory to drive C. SaveFileDialog1.FileName = "myText"; // 默认文件名 SaveFileDialog1.DefaultExt = "txt"; // 扩展名 SaveFileDialog1.Filter = "Text files (*.txt)|*.txt"; SaveFileDialog1.InitialDirectory = "c:\\"; // 初始路径 // Call ShowDialog and check for a return value of DialogResult.OK, // which indicates that the file was saved. DialogResult result = SaveFileDialog1.ShowDialog(); System.IO.Stream fileStream; if (result == DialogResult.OK) // 这里判断 { // Open the file, copy the contents of memoryStream to fileStream, // and close fileStream. Set the memoryStream.Position value to 0 to // copy the entire stream. // 真正的保存操作只有 OK 后可以 fileStream = SaveFileDialog1.OpenFile(); userInput.Position = 0; userInput.WriteTo(fileStream); fileStream.Close(); }
我想要的效果是如windows下粘帖一个文件,如果这个文件已经存在于文件夹中的时候的那个对话框,
不知道怎么实现,难道还要我自己写一个床头吗?谢谢大家,不吝赐教
{
if (MessageBox.Show("相同文件已经存在,是否覆盖?如选择不覆盖,请重新选择文件", "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
File.Copy(this.ofd.FileName.ToString(), installDirectory()+@"\"+filename, true);
}
else
{
………………
}
}
想要的是包含有‘覆盖所有’、‘是’、‘否’、‘取消’四个按钮的MessageBox!不知道怎么实现?谢谢
我只是不知道MessageBox能不能做成这样子,如果不行,我就自己做一个啦
你的需求重复了!
‘覆盖所有’、‘是’、‘否’、‘取消’,
‘覆盖所有’==‘是’;
‘否’==‘取消’
只需要2个呀,怎么会出现4个呢,真是4个的话,你的‘覆盖所有’按钮执行的东西跟“是”执行的是不是一样呢?
退一步讲,如果你真要这么做,那就自己做一个用户控件,重写messageBox的方法就行了。
大概就是这样。
共同学习,共同进步!
下面引用 msdn 的代码说明: SaveFileDialog1.CreatePrompt = true; // 文件不存在是是否提示新建
SaveFileDialog1.OverwritePrompt = true; // 文件存在是是否提示覆盖 // Set the file name to myText.txt, set the type filter
// to text files, and set the initial directory to drive C.
SaveFileDialog1.FileName = "myText"; // 默认文件名
SaveFileDialog1.DefaultExt = "txt"; // 扩展名
SaveFileDialog1.Filter = "Text files (*.txt)|*.txt";
SaveFileDialog1.InitialDirectory = "c:\\"; // 初始路径 // Call ShowDialog and check for a return value of DialogResult.OK,
// which indicates that the file was saved.
DialogResult result = SaveFileDialog1.ShowDialog();
System.IO.Stream fileStream; if (result == DialogResult.OK) // 这里判断
{
// Open the file, copy the contents of memoryStream to fileStream,
// and close fileStream. Set the memoryStream.Position value to 0 to
// copy the entire stream.
// 真正的保存操作只有 OK 后可以
fileStream = SaveFileDialog1.OpenFile();
userInput.Position = 0;
userInput.WriteTo(fileStream);
fileStream.Close();
}