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

Ask a Question related to ASP.NET Security, Design and Development.

  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. Similar Questions and Discussions

    1. Error in delete file using NET:FTP module
      I am very new to perl. I use following script to delete a file on ftp server. $ftpobj -> delete($fileName) or $newerr=1; print "cannot delete...
    2. The file is being used by some other process
      hi , Am trying to read from and write to a same xml file.i have no prob when reading the xml file.but when i write to the same file i get the...
    3. File IO won't delete txt file
      Hi, I just wrote this script so that when I change something in a list in the projector, this list is saved in an external txt file.. the problem...
    4. process .wav file?
      I would like to play a very short sound effect( .wav file ) repeatedly. ############################################ aFile = File.new("foo.wav",...
    5. How to delete a file from the file system
      Hi, Is there any module which has methods that can be used to delete a file from the filesystem in the windows NT environment. Thanks in...
  3. #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" <valerial@frlp.utn.edu.ar> wrote in message
    news:31acafac.0307100713.408967ce@posting.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

Posting Permissions

  • You may not post new threads
  • You may 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