473,397 Members | 2,056 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,397 software developers and data experts.

file access problem

Hi!

Here is what I'm trying to do:

I have created a UserControl named PictureView. It holds all the images
in one directory in the Bitmap[] images variable.
The selected image is displayed in the PictureBox control.

Here is how it works.

1. I get all the filenames of the images in the specified directory
2. I open the Bitmaps (I used Bitmap.FromFile but found out that it locks
the files so I
open them using FileStream).

The user can not click "left" or "right" buttons and view the images.

The images are "bound" to an item. So if the code of an item is "1" it's
images are stored
in : (baseDir)\images\1...

The problem comes when the user presses the "delete" button. Here is what I
do then:

1. I close the file streams I dispose of ALL the images
2. I put each of the images = null;
3. I put the images[] = null;
4. I dispose of the image in the PictureBox

And I call the Garbage collector just in case...

Then I try to delete the file. Here are the errors that I get:
"Cannot delete file (correct path) because It's being used by another
process"
or
"Cannot ......... Access denied"

If I go and look at the properties of the directory I see that it is set to
"read-only" and it seems
that windows (or .net fw) is manually changing this to read-only every time
I try to add another picture
or everytime I close and re-open the application.

This is really driving me crazy :(

Help? Anyone?

Nov 16 '05 #1
4 3691
On Mon, 31 May 2004 17:47:26 +0200, Saso Zagoranski wrote:
Hi!

Here is what I'm trying to do:

I have created a UserControl named PictureView. It holds all the images
in one directory in the Bitmap[] images variable.
The selected image is displayed in the PictureBox control.

Here is how it works.

1. I get all the filenames of the images in the specified directory
2. I open the Bitmaps (I used Bitmap.FromFile but found out that it locks
the files so I
open them using FileStream).

The user can not click "left" or "right" buttons and view the images.

The images are "bound" to an item. So if the code of an item is "1" it's
images are stored
in : (baseDir)\images\1...

The problem comes when the user presses the "delete" button. Here is what I
do then:

1. I close the file streams I dispose of ALL the images
2. I put each of the images = null;
3. I put the images[] = null;
4. I dispose of the image in the PictureBox

And I call the Garbage collector just in case...

Then I try to delete the file. Here are the errors that I get:
"Cannot delete file (correct path) because It's being used by another
process"
or
"Cannot ......... Access denied"

If I go and look at the properties of the directory I see that it is set to
"read-only" and it seems
that windows (or .net fw) is manually changing this to read-only every time
I try to add another picture
or everytime I close and re-open the application.

This is really driving me crazy :(

Help? Anyone?


Hi Saso,

Consider this code:

pictureBox1.Image = Bitmap.FromFile (sFileName);

// now try to delete it
pictureBox1.Image = null;
File.Delete (sFileName);

This returns an error (file used by another process).

But if you use pictureBox1.Image.Dispose(); you won't get an error. So I
think instead of setting images[] = null try disposing them.

Hope it would help you in some way :)

lp,
Peter

Nov 16 '05 #2
If you look at the "process" I've described you can see that I do dispose
the images before setting them to null.

This is the entire code:

for ( int i = 0;i < images.Length;i++ )
{
this.fileStreams[i].Close();
this.images[i].Dispose();
this.images[i] = null;
}

images = null;
fileStream = null;

this.pictureBox1.Image.Dispose();
this.pictureBox1.Image = null;

System.GC.Collect();

Now I try to delete the file and I get the mentioned exceptions... I think
it has something to do
with Windows setting the directory "read-only"... The problem is I don't
know why or when this happens...

"Peter Jausovec" <pe************@uni-mb.si> wrote in message
news:g6***************************@40tude.net...
On Mon, 31 May 2004 17:47:26 +0200, Saso Zagoranski wrote:
Hi!

Here is what I'm trying to do:

I have created a UserControl named PictureView. It holds all the images
in one directory in the Bitmap[] images variable.
The selected image is displayed in the PictureBox control.

Here is how it works.

1. I get all the filenames of the images in the specified directory
2. I open the Bitmaps (I used Bitmap.FromFile but found out that it locks the files so I
open them using FileStream).

The user can not click "left" or "right" buttons and view the images.

The images are "bound" to an item. So if the code of an item is "1" it's
images are stored
in : (baseDir)\images\1...

The problem comes when the user presses the "delete" button. Here is what I do then:

1. I close the file streams I dispose of ALL the images
2. I put each of the images = null;
3. I put the images[] = null;
4. I dispose of the image in the PictureBox

And I call the Garbage collector just in case...

Then I try to delete the file. Here are the errors that I get:
"Cannot delete file (correct path) because It's being used by another
process"
or
"Cannot ......... Access denied"

If I go and look at the properties of the directory I see that it is set to "read-only" and it seems
that windows (or .net fw) is manually changing this to read-only every time I try to add another picture
or everytime I close and re-open the application.

This is really driving me crazy :(

Help? Anyone?


Hi Saso,

Consider this code:

pictureBox1.Image = Bitmap.FromFile (sFileName);

// now try to delete it
pictureBox1.Image = null;
File.Delete (sFileName);

This returns an error (file used by another process).

But if you use pictureBox1.Image.Dispose(); you won't get an error. So I
think instead of setting images[] = null try disposing them.

Hope it would help you in some way :)

lp,
Peter

Nov 16 '05 #3
On Mon, 31 May 2004 18:37:43 +0200, Saso Zagoranski wrote:
If you look at the "process" I've described you can see that I do dispose
the images before setting them to null.

This is the entire code:

for ( int i = 0;i < images.Length;i++ )
{
this.fileStreams[i].Close();
this.images[i].Dispose();
this.images[i] = null;
}

images = null;
fileStream = null;

this.pictureBox1.Image.Dispose();
this.pictureBox1.Image = null;

System.GC.Collect();

Now I try to delete the file and I get the mentioned exceptions... I think
it has something to do
with Windows setting the directory "read-only"... The problem is I don't
know why or when this happens...

"Peter Jausovec" <pe************@uni-mb.si> wrote in message
news:g6***************************@40tude.net...
On Mon, 31 May 2004 17:47:26 +0200, Saso Zagoranski wrote:
Hi!

Here is what I'm trying to do:

I have created a UserControl named PictureView. It holds all the images
in one directory in the Bitmap[] images variable.
The selected image is displayed in the PictureBox control.

Here is how it works.

1. I get all the filenames of the images in the specified directory
2. I open the Bitmaps (I used Bitmap.FromFile but found out that it locks the files so I
open them using FileStream).

The user can not click "left" or "right" buttons and view the images.

The images are "bound" to an item. So if the code of an item is "1" it's
images are stored
in : (baseDir)\images\1...

The problem comes when the user presses the "delete" button. Here is what I do then:

1. I close the file streams I dispose of ALL the images
2. I put each of the images = null;
3. I put the images[] = null;
4. I dispose of the image in the PictureBox

And I call the Garbage collector just in case...

Then I try to delete the file. Here are the errors that I get:
"Cannot delete file (correct path) because It's being used by another
process"
or
"Cannot ......... Access denied"

If I go and look at the properties of the directory I see that it is set to "read-only" and it seems
that windows (or .net fw) is manually changing this to read-only every time I try to add another picture
or everytime I close and re-open the application.

This is really driving me crazy :(

Help? Anyone?


Hi Saso,

Consider this code:

pictureBox1.Image = Bitmap.FromFile (sFileName);

// now try to delete it
pictureBox1.Image = null;
File.Delete (sFileName);

This returns an error (file used by another process).

But if you use pictureBox1.Image.Dispose(); you won't get an error. So I
think instead of setting images[] = null try disposing them.

Hope it would help you in some way :)

lp,
Peter


Your code works fine. I've loaded some files, run your code and then tried
to delete one file and it works fine - maybe something other is wrong.
Nov 16 '05 #4
I know it SHOULD work... And I did mention... The problem is probably with
the "read-only" property switching of the directory with the images...

So I was hoping someone could point me out to some other possibilites as
what else could
be wrong and what should I check?
"Peter Jausovec" <pe************@uni-mb.si> wrote in message
news:n7*****************************@40tude.net...
On Mon, 31 May 2004 18:37:43 +0200, Saso Zagoranski wrote:
If you look at the "process" I've described you can see that I do dispose the images before setting them to null.

This is the entire code:

for ( int i = 0;i < images.Length;i++ )
{
this.fileStreams[i].Close();
this.images[i].Dispose();
this.images[i] = null;
}

images = null;
fileStream = null;

this.pictureBox1.Image.Dispose();
this.pictureBox1.Image = null;

System.GC.Collect();

Now I try to delete the file and I get the mentioned exceptions... I think it has something to do
with Windows setting the directory "read-only"... The problem is I don't
know why or when this happens...

"Peter Jausovec" <pe************@uni-mb.si> wrote in message
news:g6***************************@40tude.net...
On Mon, 31 May 2004 17:47:26 +0200, Saso Zagoranski wrote:

Hi!

Here is what I'm trying to do:

I have created a UserControl named PictureView. It holds all the images in one directory in the Bitmap[] images variable.
The selected image is displayed in the PictureBox control.

Here is how it works.

1. I get all the filenames of the images in the specified directory
2. I open the Bitmaps (I used Bitmap.FromFile but found out that it

locks
the files so I
open them using FileStream).

The user can not click "left" or "right" buttons and view the images.

The images are "bound" to an item. So if the code of an item is "1" it's images are stored
in : (baseDir)\images\1...

The problem comes when the user presses the "delete" button. Here is

what I
do then:

1. I close the file streams I dispose of ALL the images
2. I put each of the images = null;
3. I put the images[] = null;
4. I dispose of the image in the PictureBox

And I call the Garbage collector just in case...

Then I try to delete the file. Here are the errors that I get:
"Cannot delete file (correct path) because It's being used by another
process"
or
"Cannot ......... Access denied"

If I go and look at the properties of the directory I see that it is set
to
"read-only" and it seems
that windows (or .net fw) is manually changing this to read-only every

time
I try to add another picture
or everytime I close and re-open the application.

This is really driving me crazy :(

Help? Anyone?

Hi Saso,

Consider this code:

pictureBox1.Image = Bitmap.FromFile (sFileName);

// now try to delete it
pictureBox1.Image = null;
File.Delete (sFileName);

This returns an error (file used by another process).

But if you use pictureBox1.Image.Dispose(); you won't get an error. So

I think instead of setting images[] = null try disposing them.

Hope it would help you in some way :)

lp,
Peter


Your code works fine. I've loaded some files, run your code and then tried
to delete one file and it works fine - maybe something other is wrong.

Nov 16 '05 #5

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

Similar topics

23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the...
5
by: Tim Eliot | last post by:
Just wondering if anyone has hit the following issue and how you might have sorted it out. I am using the command: DoCmd.TransferText acExportMerge, , stDataSource, stFileName, True after...
3
by: Joe Costa | last post by:
I have written the following code to search for the right file depending on the startup file for "Client Access". The menu database that I made will load the correct config file specific for each...
11
by: stu | last post by:
I have several databases that are opened using various versions of Access and VB. Up till recently everything worked fine, then I started getting a variety of lock file error messages, both on my...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
7
by: Mark | last post by:
Hello, I have researched and tried every thing I have found on the web, in groups and MS KB articles. Here is what I have. I have a Windows 2000 Domain Controller all service packs and...
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
4
by: Salad | last post by:
I have a situation where some, not all, users get the message "Couldn't find file "F:\AccessApps\AppName.mdw". This file is required for startup". My app the users are attempting to access is...
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.