Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I m using windows application. Suppose i have embedded a text file named file.txt, when i click a button, it should copy it to any specified location with name file1.txt and when click again it should copy it again with name file2.txt...and so on. Help plz.
Posted
Comments
[no name] 22-Jun-14 8:40am    
What have you tried to do for yourself? What was the problem with what you tried?

1 solution

So when it comes to time to save it, read the folder it is going to, and look at tahe names:
C#
string[] paths = Directory.GetFiles(@"D:\Temp\", @"file*.txt");
You can then work out the highest current number from that:
C#
int max = 0;
foreach (string path in paths)
    {
    string justTheName = Path.GetFileNameWithoutExtension(path);
    Match m = Regex.Match(justTheName, @"\d+$");
    if (m.Success)
        {
        int i = int.Parse(m.Value);
        max = Math.Max(max, i);
        }
    }
string newFileName = string.Format(@"D:\Temp\file{0}.txt", max + 1);
 
Share this answer
 
Comments
Pankaj Mahor 22-Jun-14 12:37pm    
Thanx but where to put embedded text file path?

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