in my windows form app user can add image in a folder in hard drive with saveFileDialog. How can I change the name of image instead of OverwritePrompt alert with adding a variable integer to the name of image?
You should implement a check of the file name just before saving :
int i = 1;
while(File.Exists(Directory.GetCurrentDirectory()
+ "\" + saveFileDialog.FileName)
{
saveFileDialog.FileName = saveFileDialog.FileName + "_" + i;
i++;
}
This needs to go just before opening the stream to write the file:
System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog.OpenFile();
// Write to your file
fs.Close();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.