h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Increment File names If File already exists in C#.Net

private void FileNameIncrement(string SourcePath, string DesignationPath)
        {
            DirectoryInfo dir = new DirectoryInfo(SourcePath);
           
            string fileName = dir.Name;
            string fileNamewithoutExtension = Path.GetFileNameWithoutExtension(DesignationPath + "\\" + fileName);
            string fileExtention = Path.GetExtension(DesignationPath + "\\" + fileName);
            string[] files = Directory.GetFiles(DesignationPath);
            int count = files.Count(file => { return file.Contains(fileName); });
            string newFileName = (count == 0) ? fileName : String.Format("{0} ({1})" + fileExtention, fileName, count +

1);

            if (File.Exists(DesignationPath + "\\" + fileName))
            {
                File.Copy(SourcePath, DesignationPath + "\\" + newFileName);
            }
            else
            {
                File.Copy(SourcePath, DesignationPath + "\\" + fileName);
            }
        }

 string OutputPath = @"C:\Documents and Settings\Naraayanan\My Documents\Downloads";
            FileNameIncrement(textBox1.Text, OutputPath);