开发者

C# Insert directory structure into a rich text box on form

private void button6_Click(object sender, EventArgs e)
{
    string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
}

And I have a RichTextBox:

private void richTextBox4_TextChanged(object sender, EventArgs e)
{
}

How can I return / output the data 开发者_JAVA百科from the method into the RichTextBox?


Once you get the filenames, you can use Enumerable.Aggregate to turn them into a string and set that string as the text for the Rich Text Box:

private void button6_Click(object sender, EventArgs e)
{
    richTextBox4.Text = 
        Directory.GetFiles(@"C:\MyDir\")
                 .Aggregate("", (text, pathName) => 
                     text += String.Format("{0}\n", pathName))
                  );
}


foreach(string path in filePaths) {
    richTextBox4.AppendText(path + Environment.NewLine);
}


string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
richTextBox4.Text = string.Join(Environment.NewLine, filePaths);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜