Create a text file and write to it
vb.net
Solution
In more recent version of Windows, the root of the C: drive is read-only by default. Try putting the file in another folder.
Problem
I want to create a text file and write some text into this file, but my code cannot create the text file. Error message: ``` UnauthorizedAccessExcepion was unhandled by user code Access to the path 'c:\save.txt' is denied. ``` My code: ``` Dim fileLoc As String = "c:\save.txt" Dim fs As FileStream = Nothing If (Not File.Exists(fileLoc)) Then fs = File.Create(fileLoc) Using fs End Using End If If File.Exists(fileLoc) Then Using sw As StreamWriter = New StreamWriter(fileLoc) a = "Test: " + TextBox1.Text c = "==============================================" sw.Write(a) sw.Write(c) End Using End If ```