how to copy text file in text box using c#?
i like to copy the who开发者_开发百科le textfile into multiline textbox ,how can i do these?
textBox1.Text = System.IO.File.ReadAllText(path);
Use the ReadAllLines
method to read the file as an array of strings, and put that in the textbox:
TheTextBox.Lines = File.ReadAllLines(fileName);
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;
}
string value1 = System.IO.File.ReadAllText("C:\\file.txt");
System.IO.File.WriteAllText("C:\\file.txt","Hello!");
using (StreamReader sr = new StreamReader(path))
{
textbox1.Text = sr.ReadToEnd());
}
using (StreamReader reader = File.OpenText(@"C:\your_file.txt"))
myTextBox.Text = reader.ReadLine();
精彩评论