Database Reference
In-Depth Information
b. Set the Multiline property to True.
c. Set the Size property to 301, 90.
13. Your FileExceptionHandling form will look like Figure 11-1.
Figure 11-1. File-handling form in design view
14. Now it's time to write the code.
15. Double-click the Write To File button, and start adding the code.
16. First add a using statement for file-related operations, navigate to the using
statements in your code editor on the top, and the add following at the end:
using System.IO;
17. Now add the following code for writing text to the file from Listing11-1:
Listing11-1. btnWriteToFile_Click
StreamWriter sw = new StreamWriter(txtFileWritePath.Text, true);
sw.WriteLine(txtFileText.Text);
sw.Close();
18. Double-click the Read File button, and add the following code for reading
content from a file from Listing 11-2:
Listing11-2: btnReadFile_ClickStreamReader sr = new StreamReader(txtFileReadPath.Text);
txtFileContent.Text = sr.ReadToEnd();
sr.Close();
 
Search WWH ::




Custom Search