File access error

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.

Advertisements

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

Advertisements

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

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!