C# 如何打开 保存文件? 我的设置是这样,两个按钮button1 button2 两个 textbox1 textbox2 .点击button1 选择txt文件,在textbox1中显示目录,点击button2 选择txt文件,在textbox2中显示目录, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 打开OpenFileDialog保存SaveFileDialog button选择txt文件?什么意思你意思是弹出像fileupload一样的浏览窗口吗? LZ是不是想点击button1 然后弹出选择文件对话框,选中要打开的文件后在textbox1中显示选中文件的全路径点击button2后弹出保存文件的对话框,输入文件名后在textbox2中显示保存文件的全路径C#中提供了 打开 OpenFileDialog 和 保存 SaveFileDialog两个控件,只要拖到窗体中就可以使用了代码//buton1点击方法private void button1_Click(object sender,System.EventArgs e){ if(OpenFileDialog1.ShowDialog() == DialogResult.OK) { this.textbox1.Text = OpenFileDialog1.FileName; }}//buton2点击方法private void button2_Click(object sender,System.EventArgs e){ if(SaveFileDialog1.ShowDialog() == DialogResult.OK) { this.textbox2.Text = SaveFileDialog1.FileName; }} 呵呵,我是新手。LVSmile 你好,我是想点击button1读取txt文件,点击button2选择保存目录,然后有个button3点击后,自动将选择的txt文件转换成xml文件并保存,该怎么做啊?谢谢 List<string> lst=new list<String>(File.ReadAllLines(""));private void button2_Click(object sender,System.EventArgs e){ if(SaveFileDialog1.ShowDialog() == DialogResult.OK) { this.textbox2.Text = SaveFileDialog1.FileName; }}foreach(string s in lst){//写入XML,什么格式} try { string folderPath = textBoxInput.Text; DirectoryInfo theFolder = new DirectoryInfo(folderPath); if (theFolder.Exists) { DisplayFolderList(theFolder.FullName); return; } FileInfo theFile = new FileInfo(folderPath); if (theFile.Exists) { DisplayFileInfo(theFile.Directory.FullName); int index = listBoxFiles.Items.IndexOf(theFile.Name); listBoxFiles.SetSelected(index, true); return; } throw new FileNotFoundException("文件或文件夹" + textBoxInput.Text + "未找到"); } catch(Exception ex) { MessageBox.Show(ex.Message); } private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { string txt = openFileDialog1.FileName; StreamReader stream1 = new System.IO.StreamReader(txt, System.Text.Encoding.Default); string str1 = stream1.ReadToEnd(); stream1.Close(); this.rtxtTaskDetails.Text = str1; } } 导出EXCEL按钮的问题 求解一句! vs2008 DataGridView问题 关于一个触发器更新问题 C#中怎么用代码映射关键词 windows service 中如何定时执行(C# 2.0)? xml序列化生成xml文档出错 c#项目外包 写一个windos服务让服务开机自动启动然后服务自动调用写好的Winfrom程序求大神帮忙 请问能不能用vs.net把ASP文件封装成dll,然后用呢?UP有分 DataSet反序列化遇到:在分析完成之前就遇到流结尾。 vs2005与mysql
OpenFileDialog
保存
SaveFileDialog
点击button2后弹出保存文件的对话框,输入文件名后在textbox2中显示保存文件的全路径
C#中提供了 打开 OpenFileDialog 和 保存 SaveFileDialog两个控件,只要拖到窗体中就可以使用了
代码//buton1点击方法
private void button1_Click(object sender,System.EventArgs e)
{
if(OpenFileDialog1.ShowDialog() == DialogResult.OK)
{
this.textbox1.Text = OpenFileDialog1.FileName;
}
}//buton2点击方法
private void button2_Click(object sender,System.EventArgs e)
{
if(SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
this.textbox2.Text = SaveFileDialog1.FileName;
}
}
private void button2_Click(object sender,System.EventArgs e)
{
if(SaveFileDialog1.ShowDialog() == DialogResult.OK)
{
this.textbox2.Text = SaveFileDialog1.FileName;
}
}
foreach(string s in lst)
{
//写入XML,什么格式
}
{
string folderPath = textBoxInput.Text;
DirectoryInfo theFolder = new DirectoryInfo(folderPath);
if (theFolder.Exists)
{
DisplayFolderList(theFolder.FullName);
return;
}
FileInfo theFile = new FileInfo(folderPath);
if (theFile.Exists)
{
DisplayFileInfo(theFile.Directory.FullName);
int index = listBoxFiles.Items.IndexOf(theFile.Name);
listBoxFiles.SetSelected(index, true);
return;
}
throw new FileNotFoundException("文件或文件夹" + textBoxInput.Text + "未找到");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string txt = openFileDialog1.FileName;
StreamReader stream1 = new System.IO.StreamReader(txt, System.Text.Encoding.Default);
string str1 = stream1.ReadToEnd();
stream1.Close();
this.rtxtTaskDetails.Text = str1;
}
}