|
-
May 20th, 2003, 08:50 AM
#1
Thread Starter
Fanatic Member
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:
File.Create("C:\TemplateTempFile.vsdir")
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?
-
May 20th, 2003, 09:12 AM
#2
Addicted Member
i believe the streamwriter object will create a non existent file automaticly......or am i wrong as usual....lol
AcE
-
May 20th, 2003, 09:28 AM
#3
Thread Starter
Fanatic Member
You are correct sir! Told you it was an easy fix - I was just looking at it too long!
Thanks!
-
May 20th, 2003, 09:31 AM
#4
-
May 20th, 2003, 09:32 AM
#5
Lively Member
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"))
-
May 20th, 2003, 09:51 AM
#6
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|