Hello,
I have a question about creating and deleting a text file. In my program, I am creating a text file using:
Creating the file works great. I do not have any problem with that. Once the file is created, I do what I need to do with it, then I want to delete it. This is where I am encountering problems.
At this point I receive a TargetInvocationException. Looking at the innerexception it displays
I don't know why the path has double slashes. It seems like the writing of the file is keeping it open.
What would be the best way to delete the file?
Thanks
I have a question about creating and deleting a text file. In my program, I am creating a text file using:
Code:
My.Computer.FileSystem.WriteAllText(pFilePath, strInfo, False)
Creating the file works great. I do not have any problem with that. Once the file is created, I do what I need to do with it, then I want to delete it. This is where I am encountering problems.
Code:
' Delete the file.
l_strFileToDelete = Application.StartupPath.Trim & "\Registration.txt"
If System.IO.File.Exists(l_strFileToDelete) = True Then
System.IO.File.Delete(l_strFileToDelete) [red]**ERROR**[/red]
End If
At this point I receive a TargetInvocationException. Looking at the innerexception it displays
Code:
cannot access the file 'C:\\...\\Registration.txt' because it is being used by another process."
I don't know why the path has double slashes. It seems like the writing of the file is keeping it open.
What would be the best way to delete the file?
Thanks