Okay so I have been searching for the answer to this for ages and just can't seem to find it. All i want to do is create a text file then write "0" (zero) to it.
It is for a larger project but this is the code that I have been working with:
Public Class Loading
Dim Path As String = "C:\NAME.txt"
Private Sub FileCreate()
Dim file As System.IO.FileStream
file = System.IO.File.Create(Path)
My.Computer.FileSystem.WriteAllText(Path, "0", False)
MsgBox("File created")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If My.Computer.FileSystem.FileExists(Path) Then
MsgBox("File Exists")
Else
MsgBox("File Missing. Will create")
Call FileCreate()
End If
End Sub
End Class
It all seems to work fine until it tries to write "0" to the .txt file. It comes up with an error saying that the process cannot access the file because another process is using the that it just created! I have checked and the only process using it is the one above. Sorry if this is a really simple problem, I am only learning at the moment. As I mentioned I have been looking everywhere for a solution but I cannot seem to find anything. This is my first time posting a new thread so is there anything else I should or should have mentioned? Any help is appreciated.
Thanks in advance,