DirectoryInfo and FileInfo classes locking files

  • Thread starter Thread starter David Turner
  • Start date Start date
D

David Turner

I have created an ASP.NET page that uses the
System.IO.DirectoryInfo.GetFiles() method to get a list of files in a
specific directory on our web server. (I simply use this list to build some
javascript code). I'm never opening the files or accessing them in any
other way.

Problem is, that once this ASP.NET page is accessed, we can then no longer
delete or rename any of the files in that directory unless we restart IIS.

If I try and delete them using the System.IO.File.Delete() method I get the
following exception:

System.IOException
The process cannot access the file "..." because it is being used by another
process.

Any Ideas?
 
Hi

Strange. I tried this on my machine(running ASP.Net1.1)
and it workd fine. Im able to delete the files even after
the page is accessed!!!!

watch for linewraps

Dim l_objDirInfo As New DirectoryInfo
(TextBox1.Text)
Dim l_objFilesInfo() As FileInfo =
l_objDirInfo.GetFiles()
Dim l_objFileInfo As FileInfo
For Each l_objFileInfo In l_objFilesInfo
Response.Write(l_objFileInfo.Name)
Next
l_objDirInfo = Nothing

Are u opening file handles elsewhere by mistake!!!

regards,

sr
 
My bad!

The javascript that I was building actually referenced another aspx page for
each image, and I was using the image.fromfile method which was holding onto
the file. As soon as I switched to the image.fromstream method, things
started working great.
 
Back
Top