Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-06
4
Medium Priority
?
542 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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

604 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