469,301 Members | 2,156 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,301 developers. It's quick & easy.

DirectoryInfo and FileInfo classes locking files

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?
Jul 19 '05 #1
2 9083
SR
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
-----Original Message-----
I have created an ASP.NET page that uses the
System.IO.DirectoryInfo.GetFiles() method to get a list of files in aspecific directory on our web server. (I simply use this list to build somejavascript code). I'm never opening the files or accessing them in anyother way.

Problem is, that once this ASP.NET page is accessed, we can then no longerdelete 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 thefollowing exception:

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

Any Ideas?
.

Jul 19 '05 #2
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.
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Poppy | last post: by
3 posts views Thread by Dmitri Shvetsov | last post: by
reply views Thread by Andreas Palm | last post: by
1 post views Thread by Christopher Campbell | last post: by
3 posts views Thread by rao | last post: by
2 posts views Thread by Joecx | last post: by
3 posts views Thread by deciacco | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.