Solved

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

Posted on 2006-11-06
4
522 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

19 Experts available now in Live!

Get 1:1 Help Now