我的设置是这样,两个按钮button1 button2 两个 textbox1 textbox2 .
点击button1 选择txt文件,在textbox1中显示目录,
点击button2 选择txt文件,在textbox2中显示目录,

解决方案 »

  1.   

    打开
    OpenFileDialog
    保存
    SaveFileDialog
      

  2.   

    button选择txt文件?什么意思你意思是弹出像fileupload一样的浏览窗口吗?
      

  3.   

    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;
        }
    }
      

  4.   

    呵呵,我是新手。LVSmile 你好,我是想点击button1读取txt文件,点击button2选择保存目录,然后有个button3点击后,自动将选择的txt文件转换成xml文件并保存,该怎么做啊?谢谢
      

  5.   

    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,什么格式
    }
      

  6.   

    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);
                }
      

  7.   

    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;
                }
            }