how to copy text file in text box using c#?
10,249
Solution 1
textBox1.Text = System.IO.File.ReadAllText(path);
Solution 2
Use the ReadAllLines
method to read the file as an array of strings, and put that in the textbox:
TheTextBox.Lines = File.ReadAllLines(fileName);
Solution 3
Use classes from System.IO
namespace (e.g. File
).
using (FileStream fileStream = File.OpenRead("C:\your_file.txt"))
using (StreamReader streamReader = new StreamReader(fileStream))
{
string fileContent = streamReader.ReadToEnd();
myTextBox.Text = fileContent;
}
Author by
ratty
I Am Software developer from india.I am working as software developer in C#.net for past 1 Year .Contact me thorugh [email protected].
Updated on June 04, 2022Comments
-
ratty almost 2 years
i like to copy the whole textfile into multiline textbox ,how can i do these?