开发者

how to copy text file in text box using c#?

开发者 https://www.devze.com 2023-01-25 07:49 出处:网络
i like to copy the who开发者_开发百科le textfile into multiline textbox ,how can i do these? textBox1.Text = System.IO.File.ReadAllText(path);

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();
0

精彩评论

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