English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I wrote this script to create thumbnails. Most of the time it works fine, but once in a while ASP.NET locks the file and I get this error: The process cannot access the file 'my_file.jpg' because it is being used by another process. Anyone know what is going on a a fix?

Sub ResizeImage()
Dim bmpOriginal As New System.Drawing.Bitmap(Server.MapPath("images/crop/" & Request("photo")))

Dim bmpNew As New System.Drawing.Bitmap(bmpOriginal, 100, 100)
Response.ContentType = "image/gif"

bmpNew.Save(Server.MapPath("images/temp/" & Request("photo")), System.Drawing.Imaging.ImageFormat.Jpeg )

System.IO.File.Copy(Server.MapPath("images/temp/" & Request("photo")), Server.MapPath(".images/" & Request("photo")), True)
System.IO.File.Delete(Server.MapPath("images/temp/printads/" & Request("photo")))

bmpOriginal.Dispose()
bmpNew.Dispose()

Response.Redirect ("default.asp?action=done")

End

2007-03-06 05:22:04 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

The exception is thrown on this line:
System.IO.File.Delete(Server.M... & Request("photo")))

How would I close the handle to the BMP file?

2007-03-06 05:50:27 · update #1

1 answers

you might need to close the handle to the BMP file, Dispose() might not do the trick.

The other thing you can do is put a lock {... } statement around the function body, this way it will be threadsafe, which it currently isn't.


What line is the exception thrown on?

2007-03-06 05:35:30 · answer #1 · answered by fixedinseattle 4 · 0 0

fedest.com, questions and answers