471,067 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,067 software developers and data experts.

Delete a File

I have a simple image gallery where I want to allow users to delete files.
The problem I have is that after an image is displayed in the browser, I am
not able to delete the file because "The process cannot access the file ...
It is being used by another process". I also get this error when trying to
delete through explorer on the server. I can delete the file if I stop the
Web Server service... Is there a way around this?

Here is the code that fails:
System.IO.File.Delete(Page.MapPath(path_ &
clickedLink.Attributes.Item("photo_file")))
System.IO.File.Delete(Page.MapPath(path_ & "Thumbs/" &
clickedLink.Attributes.Item("photo_file")))
Nov 18 '05 #1
1 1772
On Fri, 3 Sep 2004 09:13:04 -0700, Matt Hamilton
<Ma**********@discussions.microsoft.com> wrote:
I have a simple image gallery where I want to allow users to delete
files.
The problem I have is that after an image is displayed in the browser, I
am
not able to delete the file because "The process cannot access the file
...
It is being used by another process". I also get this error when trying
to
delete through explorer on the server. I can delete the file if I stop
the
Web Server service... Is there a way around this?

Here is the code that fails:
System.IO.File.Delete(Page.MapPath(path_ &
clickedLink.Attributes.Item("photo_file")))
System.IO.File.Delete(Page.MapPath(path_ & "Thumbs/" &
clickedLink.Attributes.Item("photo_file")))


How are you displaying the images? In Windows apps this can happen using
some controls that lock the file....I usually load images into memory this
way:

Dim fs As New FileStream(Server.MapPath(imageSrc), FileMode.Open,
FileAccess.Read)
Dim image As System.Drawing.Image = System.Drawing.Image.FromStream(fs)

then do as I want with it...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Jobs | last post: by
5 posts views Thread by | last post: by
23 posts views Thread by da Vinci | last post: by
5 posts views Thread by wo20051223 | last post: by
3 posts views Thread by Arpan | last post: by
7 posts views Thread by Anil Gupte | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.