System.IO Exception - File being used, when using thumbnail images

Hi, I've created a page where a user can upload a zip file of images and display the list, the HTML list includes a thumbnail of the image eg: "<img src="thumb.aspx?p=blah">". To keep the thumbnail images seperate to the working directories for the unzipping/storage processes; A folder "temp" is used within the users directory. Whenever the thumb.aspx page is used, the image is copied from the "unzipped" directory to the "temp" directory, and the thumb is created using the "temp" directory as the source.

The problem is on irregular occasions after debugging a system.IO.exception is thrown, saying that the file is being used.

I'm disposing of objects, flushing and ending responses; but still seams to keep hold of the image files. If I do nothing for around 10 seconds lets go of the files and all is well.

Any Ideas?

Source for thumb.aspx

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If ((IsPostBack = False) And (Request.Params("sl") <> Nothing) And (Request.Params("ct") <> Nothing) And (Request.Params("fn") <> Nothing)) Then

Dim sSourceLocation As String = Request.Params("sl").Trim.ToLower

Dim sContentType As String = Request.Params("ct").Trim.ToLower

Dim sFN As String = Request.Params("fn").Trim.ToLower

Dim sPath, sExt As String

Dim p As IPrincipal = HttpContext.Current.User

Dim sPath_Temp As String = ConfigurationSettings.AppSettings("pathUsersFiles") & p.Identity.Name.Trim & ConfigurationSettings.AppSettings("path_Root_Temp")

If (Directory.Exists(sPath_Temp) = False) Then Directory.CreateDirectory(sPath_Temp)

Dim objImg As System.Drawing.Image

Dim objImg_Thumb As System.Drawing.Image

Dim objBitmap As Bitmap


Select Case sSourceLocation

Case "unzip"

sPath = ConfigurationSettings.AppSettings("pathUsersFiles") & p.Identity.Name.Trim & "\Unzip\"

End Select

Dim bImgExists As Boolean = True

Select Case sContentType

Case "image/bmp"

sExt = ".bmp"

Case "image/jpg"

sExt = ".jpg"

Case "image/jpeg"

sExt = ".jpg"

Case "image/gif"

sExt = ".gif"

Case Else

bImgExists = False

End Select

sPath &= sFN & sExt

If (File.Exists(sPath) = False) Then bImgExists = False

If (bImgExists = True) Then

File.Copy(sPath, sPath_Temp & Path.GetFileName(sPath), True)

sPath = sPath_Temp & Path.GetFileName(sPath)

WaitForFSO(sPath, 1000)

objImg = System.Drawing.Image.FromFile(sPath)

Response.ContentType = sContentType

objImg_Thumb = objImg.GetThumbnailImage(25, 25, AddressOf ThumbnailCallback, System.IntPtr.Zero)

objImg_Thumb.Save(Response.OutputStream, ImageFormat.Jpeg)





sContentType = "image/jpg"

objBitmap = New Bitmap(25, 25)

Dim objGraphics As Graphics

objGraphics = Graphics.FromImage(objBitmap)


objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg)




End If

Catch ex As Exception

objImg = System.Drawing.Image.FromFile(ConfigurationSettings.AppSettings("pathClearImg"))

Response.ContentType = "image/gif"

objImg.Save(Response.OutputStream, ImageFormat.Gif)








End Try

End If

End Sub

Public Shared Sub WaitForFSO(ByVal sFN As String, ByVal iMilli As Integer)

Dim dtStart As DateTime = DateTime.Now

Dim ts As New TimeSpan(0)

While True


ts = DateTime.Now.Subtract(dtStart)

Dim fs As New FileStream(sFN, FileMode.Open, FileAccess.Read, FileShare.None)



Catch exc As IOException

If ts.Milliseconds > iMilli Then

Throw New FileLoadException(sFN, iMilli, exc)

End If


GoTo ContinueWhile

End Try


End While

End Sub

Private Function ThumbnailCallback() As Boolean

Return False

End Function

8/3/2005 11:52:11 AM 1803 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 39


Similar Artilces:

help image layout text using System.Drawing.Imaging; using System.Drawing;
using System.Drawing; using System.Drawing.Imaging;public partial class _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) {Image img1 = Image.FromFile(Server.MapPath("1.bmp"), true); Image img2 = Image.FromFile(Server.MapPath("2.bmp"), true);Bitmap img = new Bitmap(300, 300, PixelFormat.Format24bppRgb);Graphics g = Graphics.FromImage(img); g.DrawImageUnscaled(img1, 0, 0, img1.Width, img1.Height); g.DrawImage(img2, 100, 100, 50, 50);Font font = new Font("Arial", 20); SolidBrush brush = new SolidBrush(Color.Black);st...

How to use net use?
Please can any one tell me how to use the dos command net use properly? I have read the help but can't seem to get it to work. Keep getting sytax error message. Thanks in advance. "Beowulf" <> wrote in message news:9krutk$puu$ > Please can any one tell me how to use the dos command net use properly? > > I have read the help but can't seem to get it to work. Keep getting sytax > error message. what are you trying to do? There are about 50 options to "net use" that do a ton of different thin...

When to use ( and when to use ((?
I'm just not getting it. When do you use ( in a statement, when do you need to use ((, and is the space after either or both mandatory? For example, I coded this statement: if (( $_ eq $bad_guys_ip )) { more_stuff_here }; Why the two (( in an if? And why does it seem to not work when I miss the space after the ((? Thanx! Mark me as... /Corn-fused|Dense/ > I'm just not getting it. >=20 > When do you use ( in a statement, when do you need to use ((, and is > the space after either or both mandatory? >=20 > For example, I coded this sta...

Sending SMS using or using or
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

Using Using
I have just completed reading a chapter in my book on performance. The books says to speed up performance on your web site you should use the using statement when opening connections. My question is how do you catch errors if you are using this as apposed to a try catch block.thanksBryan  Why would you use it as an alternative to a try/catch statement. Couldn't you just do something like  public void UsingSomeMethod() { try { SomeMethod(); } catch(SomeException e) { /// do something useful }}public void SomeMethod() { using (Something) { ...

Sending Mail Using System.Net.Mail with out using User credentials
HI, I have an application where in i send mails based on some condition, the user is already authenticated, so i need not check the User Credentials.Right now this is how the piece lokks:- mailClient.Credentials = new NetworkCredential(USERID, USER_PWD,DOMAIN); I want to send the mail, with out validating the user credentials, Can i skip the above line. Please post aqlong with the sample code.   Thanx in Advance. Anil Kumar.   I think you cannot skip. but store user credentials in session variables after login and then pass.If this post was useful to you, please mark it as...

Using the System.Net.WebClient to Retrieve Image
Hey,I need to save images (on my code) from a URL, ie:http://localhost/pdfthumbnail.aspx?index=0&path=FILE_NAME.pdf&dpi=8&borderwidth=13&bordercolor=808080From what I read in 1.1 you can use:  System.Net.WebClient  for this. < read >I'm using 2.0 and System.Net.WebClient is obsolete, what can I do?Cheers!- Aron I use WebRequest myself. Check it out you can download the image in your computer. Cheers Al  CheersAlMy BlogMapStats.NETPlease click on 'Mark as Answer' if this post answered your question!...

How to rename folder using System.IO.Directory in
Hello,  How to rename folder by using System.IO.Directory. I created new folder using Directory.CreateDirectory(PhysicalPath) Now i want to rename folder. Is it possible? Thank you System.IO.Directory.Move(oldname, newname)  David WierMCP/ - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one control!Calendar Express - The Best HTML Calendar Generator on the web!(Please 'Mark as Answer' when it applies) Hi Then what about files inside fo...

How to use the arguments to use() in the package being used
Howdy,=20 The subject says it all believe it or not :) What I'm trying to figure out is how to pass an argument=20 (pragma I believe is the proper term) to use() and do=20 sonethign in the package based on it. I've looked at source but can't seem to track it down.=20 (Similar idea as to CGIs -oldstyle_urls -newstyel_urls) What I'd like to do is something like this: # for old time's sake we'll just use our favorite module use Foo::Monkey qw(:Foo :Bar -doamazingthings); #then in Foo::Monkey...

How to show image when we choose the image path using Fileupload using javascript
Hello Mate,I have a file upload control and i have a image control. if i choose the image path by clicking "Browse" button from the file upload , i have to show that image in the image control and this should be done by javascript, i have to validate for only image files while setting the image url to the image control currently my code is  function setimage(obj) {var image=document.getElementById ('Image1');  document.getElementById('Image1').src= obj.value; } <asp:FileUpload Width="200px" onchange="setimage(this);" ID=&quo...

Using jQuery
What are the advantages of using ScriptReference to include a jQuery source in my .NET pages as opposed to using the regular <script src='jquery.js'></script> method? Thanks.Ryan One advantage of the ScriptManager is that you can use application relative paths (e.g. ~/scripts/jquery.js).On a related note, if you're writing something that will be public facing, you might consider using Google's free CDN hosted version of jQuery. Encosia - ASP.NET, AJAX, and more.Latest article: How I handle JSON dates returned by ASP.NET AJAX  Thanks for the reply. I act...

Uses Of definitions for Android to ios using
Hello Friends; Android is a software I developed. It's the same in ios, I want to edit it to tell me when I have a problem; Code: uses ...... , Androidapi.JNI.App , Androidapi.JNIBridge , Androidapi.JNI.GraphicsContentViewtext , FMX.Helpers.Android , Androidapi.JNI.JavaTypes , Androidapi.Helpers; The above Android ios apis, how do I use ta, one-to-One exchange, you need to find? Best regards Good work > {quote:title=ugur dogan wrote:}{quote} > Hello Friends; > > Android is a software I developed. > It's the same in ios, I want to edit it to...

useing System.Net.Mail in Net 2.0
Useing C# and VWD enviroment with the Test server in VWD. Code for Mail does not work in 2.0, get an error like this:  System.Net.Mail.SmtpException was unhandled by user code Message="Failure sending mail." Source="System" line 42 which is the smtp.Send(email) line. Code for the old way in 1.1 works just fine, here is what I use (email is bogus for this) The commented line are for Net 1.1 which works. Any ideas what I need to do? Thanks using System.Net.Mail;//using System.Web.Mail; protected void Button1_Click(object sender, EventArgs e)  {  ERMessag...

Why do Sending SMTP Authenticated E-mail succeed using SmtpMail.Send() function but fail using SmtpClient.send() function ? Bugs in System.Net.Mail.SmtpClient when send a Authenticated E-mail?
I click btnOK button, the email can send OK, but click btnFail button,  the following error is displayed! why ? you can test the section code. The SMTP, username, password are valid!  Many thanks! "Syntax error, command unrecognized. The server response was: authentication failed,decode user password error" I have tested some other SMTP, somes is OK. I think there are some bugs with System.Net.Mail.SmtpClient when send a Authenticated E-mail with some SMTP!   //------------------------------------------.ASPX Code----------------------------------------...

Using Dot Net Nuke to maintain a site developed in VS.NET using C#
Hi,Does anyone know if there is a way to create a site using C# and Visual Studio.NET 2003, but then use Dot Net Nuke to allow non-technical users to add content to the site.  The current state of the site must be accessible in both VS.NET and DNN regardless of which application saved it last.  Also preferably I would like the language used to remain C# even when edited by the marketing staff, so that I can still maintain it myself using VS.NET.  Hope you understand what I mean. If this is not possible, I wonder if anyone knows what solution I am after.   Thanks in adv...

Web resources about - System.IO Exception - File being used, when using thumbnail images -

Motor vehicle exception - Wikipedia, the free encyclopedia
The exception is based on the idea that there is a lower expectation of privacy in motor vehicles due to the regulations they operate. Additionally, ...

Podcast #42 – It’s The Exception That Proves The Rule
... Language and Usage , which was frustrated by the high number of certain types of questions that were coming in. Is this podcast the exception ...

RWW News: Marco Rubio Reiterates His Opposition To Rape Or Incest Exceptions - YouTube Right Wing Watch reports on the extreme ...

Why Kevin Pietersen is the exception to the No Dickhead Rule
Something fascinating is going on in English cricket at the moment.

John Lomax 'gutted' for Issac Luke, but says finals no exception to rules
... missing a grand final to a 10-game suspension, but says the NRL judiciary must maintain consistency in its rulings and cannot make exceptions ...

India becomes the exception to US nuclear ban
President George Bush has agreed to share civilian nuclear technology with India, reversing decades of US policies designed to discourage countries ...

Is Richard Umbers, Bernie Brookes' replacement as Myer CEO, an exception?
Myer's CIO was recently elevated to the top job, but he's in a very small minority.

Men Need to Admit That Jian Ghomeshi Is No Exception
That men like Jian Ghomeshi are a terrible exception and if we as men simply stand up and say we are not as bad as that, or that we are not rapists ...

China, Thailand reach visa exception agreement
China, Thailand reach visa exception agreement People's Daily Online ... this at a forum on China's foreign diplomacy held in Beijing. Both ...

No exception allowed in graft crackdown: People's Daily
No exception allowed in graft crackdown: People's Daily - ecns The expulsion of Ling Jihua from the Communist Party of China (CPC) ...

Resources last updated: 12/15/2015 2:08:45 PM