Results 1 to 6 of 6

Thread: File access violation - used by another process

  1. #1

    Thread Starter
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681

    File access violation - used by another process

    This should be easy - but I can't seem to find the solution.

    I have the following code:
    VB Code:
    1. File.Create("C:\TemplateTempFile.vsdir")
    2. Dim swrAddTemplates As StreamWriter = (File.AppendText "C:\TemplateTempFile.vsdir")

    I get a file access violation - file used by another process - which I have determined to be the File.Create statement.

    How can I end that process?

  2. #2
    Addicted Member theonetrueace's Avatar
    Join Date
    Jan 2002
    Location
    South Alabama
    Posts
    196
    i believe the streamwriter object will create a non existent file automaticly......or am i wrong as usual....lol

    AcE

  3. #3

    Thread Starter
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    You are correct sir! Told you it was an easy fix - I was just looking at it too long!

    Thanks!

  4. #4
    Addicted Member theonetrueace's Avatar
    Join Date
    Jan 2002
    Location
    South Alabama
    Posts
    196
    Cheers

  5. #5
    Lively Member
    Join Date
    Jan 2003
    Posts
    71
    I am not sure I understand what you are trying to do, but the following eliminates the error. I don't know if it will give you the desired result.

    Dim sr As StreamWriter = File.CreateText("C:\Test.txt")
    sr.Close()
    Dim swrAddTemplates As StreamWriter = (File.AppendText("C:\Test.txt"))

  6. #6

    Thread Starter
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Yes - that was the problem - the FileStream that was created with the File.Create was not being closed before being hit by another Streamwriter.

    So I just omit the File.Create and the StreamWriter creates the file if it doesn't exist for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width