这与本网站较旧的帖子类似,但我不断收到错误消息。我想在C#WPF中创建一个按钮,打开一个对话框并保存一个文本文件以供日后阅读。此代码适用于Windows 32,但在Windows 64上崩溃。如何更改此代码以使其在两个系统上都能正常工作?我是编程初学者。WPF保存对话框(对于Windows 64)
Microsoft.Win32.SaveFileDialog saveFile = new Microsoft.Win32.SaveFileDialog(); //throws error message here
private void savebutton_Click(object sender, RoutedEventArgs e)
{
saveFile.FileName = Class1.stringjobnum;
saveFile.Filter = "CCurtain (*.cur)|*.cur";
saveFile.FilterIndex = 2;
saveFile.InitialDirectory = "T:\\Tank Baffle Curtain Calculator\\SavedTanks";
saveFile.OverwritePrompt = true;
bool? result = saveFile.ShowDialog();
if (result.HasValue && result.Value)
{
clsSaveFile.s_FilePath = saveFile.FileName;
int iDotLoc = clsSaveFile.s_FilePath.LastIndexOf('.');
string strExtTest = clsSaveFile.s_FilePath.Substring(iDotLoc);
if (strExtTest != ".cur")
clsSaveFile.s_FilePath += ".cur";
FileInfo sourceFile = new FileInfo(clsSaveFile.s_FilePath);
clsSaveFile.saveFile();
}
}
是否有某些原因使用Microsoft.Win32而不是System.Windows.Forms? – djdanlib 2011-12-28 21:00:30
你得到的错误信息是什么? – decyclone 2011-12-28 21:07:35
让SaveFileDialog在构造函数中崩溃表明您的机器相当麻烦。发布到superuser.com,询问如何让它再次稳定。 – 2011-12-28 21:41:42