Professional Web Applications Themes

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

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") ...

  1. #1

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

    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 Guest

  2. #2

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

    CLose the hanlde on Archivo object.

    Archivo.Close()

    --
    Naveen K Kohli
    [url]http://www.netomatix.com[/url]
    "Valeria" <valerialfrlp.utn.edu.ar> wrote in message
    news:31acafac.0307100713.408967ceposting.google.c om...
    > 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 Guest

Similar Threads

  1. Error in delete file using NET:FTP module
    By shellyshao in forum PERL Modules
    Replies: 3
    Last Post: February 14th, 11:18 PM
  2. File IO won't delete txt file
    By Eelco Heuvelmans webforumsuser@macromedia.com in forum Macromedia Director Lingo
    Replies: 4
    Last Post: December 4th, 01:09 PM
  3. process .wav file?
    By mike re-v in forum Ruby
    Replies: 6
    Last Post: November 9th, 12:20 AM
  4. How to delete a file from the file system
    By Chinku Simon in forum PERL Beginners
    Replies: 1
    Last Post: October 23rd, 08:33 PM
  5. Replies: 0
    Last Post: July 23rd, 09:49 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139