在打开另存为设置了默认的目录InitialDirectory 导致文件不能复制

saveDialog.FileName = "DateBase.sdf";
saveDialog.InitialDirectory = "d:\\";
saveDialog.Title = "请选择文件输入路径";
saveDialog.ValidateNames = true;
saveDialog.OverwritePrompt = false;
saveDialog.DefaultExt = "sdf";
if (DialogResult.OK == saveDialog.ShowDialog()) {
	//MessageBox.Show(saveDialog.FileName);
	string sourceDirectory = System.Environment.CurrentDirectory;
	string sourceFileName=sourceDirectory+"\\MyDatabase.sdf";
	string destFileName = saveDialog.FileName;
	//File.Delete(destFileName);
	File.Copy("d:\\out.log", "e:\\out.txt", true);
	File.Copy(sourceFileName, "e:\\DateBase.sdf",true);
	File.Copy(sourceFileName, destFileName,true);
}

 这段代码看上去貌似没有问题其实在打开saveDialog时 saveDialog.InitialDirectory = "d:\\"; 导致了System.Environment.CurrentDirectory;的结果为D:\\...

其实还是目录问题.

 

你可能感兴趣的:(Directory)