Solved

This should be easy Close this connection System.Drawing.Image.FromFile(

Posted on 2006-11-06
4
524 Views
Last Modified: 2010-08-05
Ok here is the code that I know is causing this issue but I need the code so I need a work around for this

            System.Drawing.Image scottsimg = System.Drawing.Image.FromFile(filelocation + sFilename);
            intThumbHeight = (scottsimg.Height * intThumbWidth) / scottsimg.Width;

Here is the Error
The process cannot access the file 'C:\Documents and Settings\Scott\My Documents\Visual Studio 2005\WebSites\shotdrive\img\178f8f94-8286-4f3c-bc69-c4684020fc4b\2.jpg' because it is being used by another process.


So I assume that when I open that file it is not closing a connection to it. The code that I posted is after I upload an image I need to resize it with out messing up the proportions...
0
Comment
Question by:Scripter25
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
sodalitas earned 500 total points
ID: 17884390
You need to call scottismg.Dispose() after you are done with it.
0
 
LVL 16

Expert Comment

by:muzzy2003
ID: 17884401
Can you post the code that saves the file just before the snippet you've given us?
0
 
LVL 6

Expert Comment

by:sodalitas
ID: 17884418
Just reread the question and I think I misunderstood.  You are saying that there is code that is creating the file at location filelocation + sFilename and that code is not freeing it up, so when you call FromFile() it cannot access the file?  In that case if you can post your code that is doing the uploading we can see why it's not allowing subsequent access to the file.
0
 

Author Comment

by:Scripter25
ID: 17885832
sodalitas  you were right I did attempt to use this before and it didnt work but when I tried I used it like this
scottsimg.Dispose;
Instead of this
 scottsimg.Dispose();

That is why it didnt work for me the first time.
Thank you for you help on this.....

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now