Solved

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

Posted on 2006-11-06
4
528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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