Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Guest mutant
Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...