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

Discussion in 'ASP .Net Security' started by Valeria, Jul 10, 2003.

  1. Valeria

    Valeria Guest

    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!
     
    Valeria, Jul 10, 2003
    #1
    1. Advertising

  2. CLose the hanlde on Archivo object.

    Archivo.Close()

    --
    Naveen K Kohli
    http://www.netomatix.com
    "Valeria" <> wrote in message
    news:...
    > 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!
     
    Naveen K Kohli, Jul 17, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page