![]() |
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. Dim fi2 As FileInfo = New FileInfo(fileName) fi2.Delete() -- David |
Re: File access error
On Feb 3, 4:30*pm, DavidC <dlch...@lifetimeinc.com> 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 |
Re: File access error
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: janij@removethis.dystopia.fi Business: http://www.nimacon.net/ Personal: http://www.saunalahti.fi/janij/ |
| All times are GMT. The time now is 07:29 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.