I create text file and would like to write some content to that file, but I am getting an error in the stream writer statement.
-------
Dim fileLoc As String = "d:\sample1.txt"
Dim fs As FileStream = Nothing
If (Not File.Exists(fileLoc)) Then
fs = File.Create(fileLoc)
Else
File.Delete(fileLoc)
fs = File.Create(fileLoc)
End If
Using sw As StreamWriter = New StreamWriter(fileLoc)
--------
--------
some thing
----------
----------
sw.writeline(phone)
---------
end using
The error I get is:
The process cannot access the file ‘d:\sample1.txt’ because it is
being used by another process.
It happens since you are deleting the file and soon creating it. The delete process is going on so it would allow you create the file.
Hope this code helps you.