By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,505 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,505 IT Pros & Developers. It's quick & easy.

Delete a File

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.