473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

File access denied

When I run my program, I open a picturebox with a photo loaded in to it using
the code:
PictureBox1.Image = Image.FromFile(strPath & strImage).
I then close the picture box and put in the line:
PictureBox1.Dispose()
and it still will not let me delete the file which the photo is located. It
gives me the in use error message. I need to be able to delete the photo
without closing the program. Can anyone help?

Jul 9 '06 #1
4 2904
Mark <Ma**@discussions.microsoft.comwrote:
When I run my program, I open a picturebox with a photo loaded in to it using
the code:
PictureBox1.Image = Image.FromFile(strPath & strImage).
I then close the picture box and put in the line:
PictureBox1.Dispose()
and it still will not let me delete the file which the photo is located. It
gives me the in use error message. I need to be able to delete the photo
without closing the program. Can anyone help?
The picture box doesn't dispose its image, so by disposing the picture
box you're not disposing the image. To guarantee that the image file is
closed, I recommend you create a separate FileStream in a Using
statement and load the image from that stream rather than passing a file
name. That way, the file stream definitely gets closed.

-- Barry

--
http://barrkel.blogspot.com/
Jul 10 '06 #2
Thanks for your suggestion, but I am new at this and I don't fully
understand. Can you give me a sample, please. Thanks in advance.

"Barry Kelly" wrote:
Mark <Ma**@discussions.microsoft.comwrote:
When I run my program, I open a picturebox with a photo loaded in to it using
the code:
PictureBox1.Image = Image.FromFile(strPath & strImage).
I then close the picture box and put in the line:
PictureBox1.Dispose()
and it still will not let me delete the file which the photo is located. It
gives me the in use error message. I need to be able to delete the photo
without closing the program. Can anyone help?

The picture box doesn't dispose its image, so by disposing the picture
box you're not disposing the image. To guarantee that the image file is
closed, I recommend you create a separate FileStream in a Using
statement and load the image from that stream rather than passing a file
name. That way, the file stream definitely gets closed.

-- Barry

--
http://barrkel.blogspot.com/
Jul 10 '06 #3
Mark <Ma**@discussions.microsoft.comwrote:
"Barry Kelly" wrote:
Mark <Ma**@discussions.microsoft.comwrote:

The picture box doesn't dispose its image, so by disposing the picture
box you're not disposing the image. To guarantee that the image file is
closed, I recommend you create a separate FileStream in a Using
statement and load the image from that stream rather than passing a file
name. That way, the file stream definitely gets closed.

Thanks for your suggestion, but I am new at this and I don't fully
understand. Can you give me a sample, please. Thanks in advance.
Somewhat like this (in C#):

---8<---
PictureBox pbox;

// ...

using (Stream stream = File.OpenRead("your\\path\\here"))
{
pbox.Image = Image.LoadFromStream(stream);
}
--->8---

Look up the Using statement in VB for VB syntax.

-- Barry

--
http://barrkel.blogspot.com/
Jul 10 '06 #4
Barry Kelly <ba***********@gmail.comwrote:
Mark <Ma**@discussions.microsoft.comwrote:
"Barry Kelly" wrote:
Mark <Ma**@discussions.microsoft.comwrote:
>
The picture box doesn't dispose its image, so by disposing the picture
box you're not disposing the image. To guarantee that the image file is
closed, I recommend you create a separate FileStream in a Using
statement and load the image from that stream rather than passing a file
name. That way, the file stream definitely gets closed.
Thanks for your suggestion, but I am new at this and I don't fully
understand. Can you give me a sample, please. Thanks in advance.

Somewhat like this (in C#):

---8<---
PictureBox pbox;

// ...

using (Stream stream = File.OpenRead("your\\path\\here"))
{
pbox.Image = Image.LoadFromStream(stream);
Make that FromStream, not LoadFromStream
}
--->8---

Look up the Using statement in VB for VB syntax.

-- Barry
-- Barry

--
http://barrkel.blogspot.com/
Jul 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bill Burwell | last post by:
I am converting a VB6 WebClass application to VB.Net. Used the VB upgrade tool to do the conversion - and it left me a lot of little code things to do. Did those code things and got my app to...
1
by: Edward Yang | last post by:
I setup web.config with impersonation="true". On our local server the project works great. I did the same procedures on our staging server, but it failed with an impossible error: Server Error in...
4
by: Thomas Scheiderich | last post by:
The following code works fine. It opens file reads the data and then closes. **************************************************************************** **************** Dim objFileInfo As...
3
by: Shailesh Gajare | last post by:
Hi All, I have creating an ASP.Net application with two web servers. I am uploading a file which is being uploaded on one of the server, I want to copy the uploaded file on the other server at the...
1
by: Duffman | last post by:
Hi, I have what seems to be a common problem, but the solutions I've found don't seem to work. I would like to use a web service to create a file at a UNC location in a shared file. Currently...
5
by: Joe | last post by:
I'm getting the following error when trying to call a page on a secure server. I'm not doing any impersonations or file access of any kind. The page is using PayPal and I'm wondering if PayPal has...
3
by: David Thielen | last post by:
Hi; I created a virtual directory in IIS 6.0 and my asp.net app runs fine. But when it tries to write a file I get: Access to the path is denied. - C:\Inetpub\wwwroot\RunReportASP\images ...
0
by: Elroyskimms | last post by:
I need to execute a batch file via ASP.Net. In my VB.Net code, I'm using System.Diagnostics.Process to call the batch file and its appropriate command line arguments. I'm using...
1
by: igotyourdotnet | last post by:
Ok, here is the issue: I have 2 web pages one does a file upload to a database and the other page does a FTP to a server, both pages use the c:\temp directory. The page that uploads to a database...
0
by: Andy | last post by:
Thanks Peter, I thought I'd give an update on this problem. My application had 2 assemblies that contained classed for the Data access and business logic layer. It was on one of them that I was...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.