neosven Posted April 18, 2003 Posted April 18, 2003 I'm 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 Quote
Guest mutant Posted April 18, 2003 Posted April 18, 2003 Try something like this: 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 Quote
neosven Posted April 18, 2003 Author Posted April 18, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.