Hi, In desktop application i saving the images in folders but when i save the images second time it will overwrite. so i want to save the same images in folder with rename like Picture(1).jpg.
so please help me how can i do this.
i tried the following code but images with numbers are not incremented.
- string folderPath1 = "E:\\CoachingClassImages\\HeaderInfoImages\\Logo\\";
- if (!Directory.Exists(folderPath1))
- {
- Directory.CreateDirectory(folderPath1);
- }
-
-
-
- int count = 1;
- string file = "E:\\CoachingClassImages\\HeaderInfoImages\\Logo\\" + logo_picname;
- string filename = Path.GetFileNameWithoutExtension(logo_location);
- string extention = Path.GetExtension(filename);
- string fileLocation1 = file;
- if (File.Exists(file))
- {
- System.GC.Collect();
- System.GC.WaitForPendingFinalizers();
-
- string tempFileName = string.Format("{0}({1}){2}", filename, count++, extention);
-
- File.Copy(fileLocation1, Path.Combine("E:\\CoachingClassImages\\HeaderInfoImages\\Logo\\", Path.GetFileName(tempFileName)), true);
- }
- else
- {
- File.Copy(fileLocation1, Path.Combine("E:\\CoachingClassImages\\HeaderInfoImages\\Logo\\", Path.GetFileName(filename)), true);
- }