Assuming your text box is set to multi-line...
newtextbox.AppendText("\n");
EDIT: Based on additional information, this is the revised solution.
It appears you are trying to concatenate the file names from two different directories (unhelpfully named
str
and
str1
).
First, I would build the sequence of file names using LINQ (make sure to include a using for System.Linq).
List<string> fileNames = Directory.EnumerateFiles(str)
.Concat(Directory.EnumerateFiles(str1))
.Select(path => Path.GetFileName(path))
.ToList();
richTextBox1.AppendText(string.Join("\n", fileNames));
I'll take a sec to explain the parts.
Directory.EnumerateFiles(str)
returns an enumeration of file paths in the specified path (
str
).
Then,
.Concat(Directory.EnumerateFiles(str1))
concatenates an enumeration of file paths in a second specified path (
str1
) onto the end of the original enumeration.
Next,
.Select(path => Path.GetFileName(path))
modifies the concatenated enumeration so that it now consists of the file name for each path.
Next,
.ToList()
creates a list from the enumeration.
Finally,
string.Join("\n", fileNames)
places a new line character between each element of fileNames.
I highly suggest taking a moment to learn LINQ. Its very powerful when you are manipulating sequences of items.