用于WPF窗口应用程序的savefileDialog [英] savefileDialog for WPF windows application

查看:587
本文介绍了用于WPF窗口应用程序的savefileDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WPF应用程序中,



当button1.click像下面的代码时,我正在使用savefiledialog。

 Microsoft.Win32.SaveFileDialog dlg =  new  Microsoft.Win32.SaveFileDialog(); 
dlg.FileName = Document; // 默认文件名
dlg.DefaultExt = 。text; // 默认文件扩展名
dlg.Filter = 文本文档(.txt)| * .txt; // 按扩展名过滤文件

Nullable< bool> result = dlg.ShowDialog();

if (result == true
{
string filename = dlg.FileName;
}



没有任何错误,它的运行,但它没有保存到系统。

这里我使用的是Windows Server 2008 r2企业版64位操作系统和vs2010。

你能不能告诉我这里有什么问题。

解决方案

我看到你的代码是取自 MSDN页面 [ ^ ]。他们忘了提及,你需要自己处理保存过程,因为没有引用Stream或字节数组或者你想要放入该文件的其他东西。

检查结果后,使用以下内容:

 File.WriteAllText(dialog.FileName,fileText )


In My WPF Application,

I am using savefiledialog when button1.click like below code.

Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".text"; // Default file extension
dlg.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension 

Nullable<bool> result = dlg.ShowDialog();

if (result == true)
{
   string filename = dlg.FileName;
}


With out any error its Running, but its not saving to the system.
here i am using windows server 2008 r2 Enterprise edition 64bit operating system and vs2010.
can you please tell me any thing wrong here.

解决方案

I see that your code is taken from MSDN page[^]. They forgot to mention, that YOU need to handle the save process by yourself, since there is no reference to Stream or byte array or something else you want to put into that file.
After checking the result, use something like this:

File.WriteAllText(dialog.FileName, fileText)


这篇关于用于WPF窗口应用程序的savefileDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆