File access error

Discussion in 'ASP .Net' started by DavidC, Feb 3, 2010.

  1. DavidC

    DavidC Guest

    I have an asp.net web page that reads lines from a csv file into a database
    and then deletes the file when successful. The import works fine, but when I
    go to delete it using the code below I am getting the error "The process
    cannot access the file 'D:\databases\fapay\RP Imports\filename.csv' because
    it is being used by another process." Is there a way around this? Thanks.

    Dim fi2 As FileInfo = New FileInfo(fileName)
    fi2.Delete()


    --
    David
    DavidC, Feb 3, 2010
    #1
    1. Advertising

  2. On Feb 3, 4:30 pm, DavidC <> wrote:
    > I have an asp.net web page that reads lines from a csv file into a database
    > and then deletes the file when successful.  The import works fine, but when I
    > go to delete it using the code below I am getting the error "The process
    > cannot access the file 'D:\databases\fapay\RP Imports\filename.csv' because
    > it is being used by another process."  Is there a way around this?  Thanks.
    >
    >             Dim fi2 As FileInfo = New FileInfo(fileName)
    >             fi2.Delete()
    >
    > --
    > David


    David,

    It looks like you are opening the file for write access and then
    attempting to delete it. Ensure that you close after import and try to
    open as read-only

    e.g. File.Open(path, FileMode.Open, FileAccess.Read)

    Hope this helps
    Alexey Smirnov, Feb 3, 2010
    #2
    1. Advertising

  3. Hello David,

    > I have an asp.net web page that reads lines from a csv file into a
    > database
    > and then deletes the file when successful. The import works fine, but
    > when I
    > go to delete it using the code below I am getting the error "The process
    > cannot access the file 'D:\databases\fapay\RP Imports\filename.csv'
    > because
    > it is being used by another process."


    Sounds like you have an open handle to the file. This might be because of
    the import code you are using. Are you closing the file? Can you share the
    code that does the import, as this might help us solve your issue?

    There might be other issues here affecting the file deletion as well, like
    virus scanning software, but this sounds unlikely as the file import works.
    So I'd check the code first.

    > Dim fi2 As FileInfo = New FileInfo(fileName)
    > fi2.Delete()


    By the way, you could also use the static Delete method of the File class to
    delete the file. This way, you don't need to construct the FileInfo object
    (unless you need it to something else, too).

    Hope this helps.

    --
    Regards,

    Jani Järvinen
    C# MVP
    Vantaa, Finland
    E-mail:
    Business: http://www.nimacon.net/
    Personal: http://www.saunalahti.fi/janij/
    Jani Järvinen [MVP], Feb 3, 2010
    #3
    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.
Similar Threads
  1. John Carnahan

    File Access error - writing to .txt file

    John Carnahan, Jul 18, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    783
    John Carnahan
    Jul 18, 2003
  2. david
    Replies:
    2
    Views:
    1,608
    Ken Cox [Microsoft MVP]
    Nov 24, 2003
  3. Jay
    Replies:
    2
    Views:
    1,058
  4. Alex Washtell via .NET 247

    Web Service + Anon Access, but getting 401 Access Denied Error

    Alex Washtell via .NET 247, Apr 5, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    186
    Mauro Ottaviani [MSFT]
    Apr 5, 2005
  5. Diego Fernández Santos
    Replies:
    2
    Views:
    229
Loading...

Share This Page