create new file

neosven

Member
Joined
Apr 2, 2003
Messages
5
Im having a problem to create a new file.
I use this code to create and use a file.

If Not File.Exists("lijst.txt") Then
File.Create("lijst.txt")
End If

Dim swLijst As StreamWriter = New StreamWriter("lijst.txt")

And then I get this erro :
An unhandled exception of type System.IO.IOException occurred in mscorlib.dll

Additional information: The process cannot access the file "C:\Documents and Settings\sven voet\My Documents\Sven Voet\LeveringIngave\bin\lijst.txt" because it is being used by another process.

Does anyone know how I can close this other proces and make the new file actif?

Thanks
 
Try something like this:
Code:
Dim fil as IO.File
If Not fil.Exists("somefile") Then
            Dim fs As New IO.FileStream("pathofsomefile", IO.FileMode.CreateNew)
            Dim wri as new IO.StreamWriter("somefile")
End If
 
Thanks for the tip.
I also found an other way

Dim stream As Stream
stream = File.Create("lijst.txt")
stream.Close()

The problem was that you had to close the file before you could open the streamwriter.
When you use a stream to create a file, you can do this.
 
Back
Top