Delete File Asp.NET Error: File is used by another process

V

Valeria

Please, help!
I have set Permission to Full Control to the user ASPNet_wp account to
my Security folder.
I have set UserName = "System" processModel in Machine.config
And when I want to delete File.txt I got the follow error:

The process cannot access the file
"c:\inetpub\wwwroot\MyApp\Security\File.txt"
because it is being used by another process."

My code is:
Dim strFilepath As String
Dim FileObject, oInStream, strOutput
strFilepath = Server.MapPath("seguridad/")
Dim Archivo As System.IO.File

'Crete the file
Archivo.Create(strFilepath & "File.txt")

'Write the file
Dim objStreamWriter As System.IO.StreamWriter
objStreamWriter = System.IO.File.AppendText("File.txt")
objStreamWriter.WriteLine(Trim(txtClave.Text))
objStreamWriter.Close()
objStreamWriter = Nothing

'Delete the File
If Archivo.Exists(strFilepath & "File.txt") Then
'This line causes an error!!!!
Archivo.Delete(strFilepath & "File.txt")
End If
Archivo = Nothing

Do I have to open the File in exclusive mode ?
If yes, I appreciate the code to do it... Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top