Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i save a file to a folder using:

C#
private void btnsave_Click(object sender, EventArgs e)
{
    string path = @"H:\le sensored\le sensored\images";
    string name = "Osim";
    pictureBox6.Image.Save(path + @"\" + name + ".jpg", ImageFormat.Jpeg);
}

but when i try to save another picture it overwrites the 1st one,please can i save other image in that same file path?
Posted
Updated 22-Apr-15 2:08am
v2
Comments
Richard MacCutchan 22-Apr-15 8:11am    
No, use a different filename.

When you try to save a file with a file name of an existing file
it will be overwritten.

You must use a different file name.

Maybe you should use a counter that holds the number
of saved pictures and increase it after a file has been written.

The file name could e.g. be a combination of "Osim" and the current value of the counter.

Then your files would be called e.g. Osim_1.jpg, Osim_2.jpg, Osim_3.jpg etc.
 
Share this answer
 
To do that, you will have to do one of two things:
1) Rename the existing file to something else first - File.Move[^] will do that for you, but you may have to check if that file exists as well.
2) Use a different name.

In either case, check if the file exists with File.Exists[^] first.

To use a different name, I'd suggest that you append a version number just before the file extension - and if you use an integer value to can check if it exists, and increment it if it does, then recheck.
So you would end up with
MyPic.jpg
MyPic.0001.jpg
MyPic.0002.jpg
...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900