请教各位大侠
  我如何用openFileDialog读取本机上的一个TXT文件呢   private System.Windows.Forms.OpenFileDialog openFileDialog;
   if(openFileDialog.ShowDialog() == DialogResult.OK)
  {
   string file = this.openFileDialog.?
   }   我想用file保存选中的文件内容,望各位大侠教我?

解决方案 »

  1.   

    Look up samples in msdn
    ref:
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003APR.1033/cpref/html/frlrfSystemIOFileStreamClassTopic.htm
      

  2.   

    openFileDialog是用来打开文件的,可以得到所打开的文件的文件名、文件路径等信息
    但是得不到文件里面具体的内容
      

  3.   

    打开文件private void button1_Click(object sender, System.EventArgs e)
    {
        Stream myStream;
        OpenFileDialog openFileDialog1 = new OpenFileDialog();    openFileDialog1.InitialDirectory = "c:\\" ;
        openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
        openFileDialog1.FilterIndex = 2 ;
        openFileDialog1.RestoreDirectory = true ;    if(openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            if((myStream = openFileDialog1.OpenFile())!= null)
            {
                // Insert code to read the stream here.
                myStream.Close();
            }
        }
    }
      

  4.   

    再请教whchina.小弟这方面欠缺,     // Insert code to read the stream here.
       怎样将读到的值存取出来呢
           比如  string file=myStream.?