如何保存整个文件 [英] how to save the entire document

查看:78
本文介绍了如何保存整个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想使用给定的文件名将整个文档保存在本地系统中.
我用一个文件名mcontents和三个组合框构建了一个wpf应用程序,单击一个按钮后,我想将文件及其内容保存在locla system中.iam可以仅保存名称而不保存其内容..plz帮助我

in my application i want to save the entire document in local system with a agiven filename.
i builted one wpf application with filename mcontents and three comboboxes,on click of a button i want to save the file along with its contents in locla system.iam able to save the file with only name but not its contents ..plz help me

推荐答案

尝试一下
在此示例中,"textBox1.Text"是我要保存到文件中的数据.

Try this
In this example "textBox1.Text" is the data I want to save to the file.

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

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

if (result == true)
{
    // Save document
    string fileName = dlg.FileName;

    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fileName))
    {
        writer.Write(textBox1.Text);
        writer.Close();
    }
}



当然,您将需要根据需要对其进行修改.



and of course you will want to modify this for your needs.


这篇关于如何保存整个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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