Why are you doing this:
System.IO.File.WriteAllText("myfile.txt", RichTextBox1.Text)
Dim sw As New System.IO.StreamWriter("myfile.txt")
End If
End Sub
There are a huge number of things wrong with this, but the important ones are:
1) It assumes the text file is in the application executable directory: this works in development, but fails in production because the app is installed to the "Program Files" folder, and that is read only unless your app is elevated - which means UAE. See here
Where should I store my data?[
^] for better places - it's C# code instead of VB, but it should translate very easily.
2) If you look at the StreamWriter documentation:
MSDN[
^], it says:
If the file exists, it is overwritten; otherwise, a new file is created.So the date you just wrote to the file with WriteAllText is deleted by the following instruction...
3) (and this is the one you noticed) StreamWriter opens the file for writing - which means it takes an exclusive lock on the file - so you can't do anythign else to teh file until the StreamWriter is closed - and since you don't close it, or Dispose the instance, itr will stay open until the Garbage Collector gets round to deleting it - which could be tomorrow, next week, next month...or when the app closes, whichever comes first.