C#关于txt文件复制保存的问题
现在我想把一个txt文件复制,在复制之前让用户选择保存位置,这个用c#语言怎么实习实现? --------------------编程问答-------------------- 不是有savedialog对话框组件吗,然后用 System.IO.File.Copy 复制文件 --------------------编程问答-------------------- 让用户选择保存的文件用SaveFileDialog:http://msdn.microsoft.com/zh-cn/library/microsoft.win32.savefiledialog.aspx
复制,可以读取再保存
File.ReadAllText(String)
File.WriteAllText(String, String)
也可以拷贝
File.Copy(String, String)
参考:
File Methods
http://msdn.microsoft.com/en-us/library/3z2ck8eh.aspx
--------------------编程问答-------------------- using System;
using System.IO;
using System.Windows.Forms;
namespace CopyFile
{
public partial class FormMain : Form
{
#region 常量
private const string Filter = "文本文件(.txt)|*.txt";
private const string TitleSource = "请选择要复制的文件";
private const string TitleDest = "请设置要复制到的文件";
#endregion
#region 构造函数
public FormMain()
{
InitializeComponent();
}
#endregion
#region 控件事件
private void ButDoCopy_Click(object sender, EventArgs e)
{
var ofd = new OpenFileDialog { Filter = Filter, Title = TitleSource };
if (ofd.ShowDialog() != DialogResult.OK) return;
var sfd = new SaveFileDialog { Filter = Filter, Title = TitleDest };
if (sfd.ShowDialog() != DialogResult.OK) return;
try
{
File.Copy(ofd.FileName, sfd.FileName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
#endregion
}
}
补充:.NET技术 , C#