打印输入文件的转换语法错误

时间:2011-12-15 16:59:34

标签: c# winforms visual-studio-2010

我想将输入文件数据打印到文本框但是这里显示的错误是代码

 private void richTextBox1_TextChanged(object sender, EventArgs e)
    {
        File.WriteAllLines(file1, richTextBox1.Text);  // file1 is my input file

    }

错误是:

// Error 3 Argument 1: cannot convert from 'System.Collections.Generic.List<string>' to 'string'
// Error 4 Argument 2: cannot convert from 'string' to 'System.Collections.Generic.IEnumerable<string>'

所以我的问题是如何将列表转换为字符串和字符串为IEnumerable<string>

  private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            OpenFileDialog fdlg = new OpenFileDialog();
            fdlg.Title = ".cs File Detector";
            fdlg.InitialDirectory = @"c:\";
            fdlg.Filter = "cs files (*.cs)|*.cs";
            fdlg.FilterIndex = 2;
            fdlg.RestoreDirectory = true;
            if (fdlg.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = fdlg.FileName;
            }
        }
        catch (Exception eee)
        {
            MessageBox.Show(eee.ToString());
        }

    }

我从这里调用文件所以现在应该对文本框的readtext做同样的事情吗?

2 个答案:

答案 0 :(得分:1)

你想阅读,而不是写:

richTextBox1.Text = File.ReadAllText(textBox1.Text);

答案 1 :(得分:0)

也许你想用WriteAllText代替?