revised!
I want to create a file say called test.txt.
if that file already exists I want to create file called test1.txt and so on.
revised!
I want to create a file say called test.txt.
if that file already exists I want to create file called test1.txt and so on.
Pass in FileMode.Create
to File.Open(string, FileMode)
when opening the file and it will create a new file every time.
FileStream file = File.Open("text.txt", FileMode.Create);
Here is a short example:
using System;
using System.IO;
class Program
{
static void Main()
{
String file = "text.txt";
if (File.Exists(file))
File.Delete(file);
FileStream fs = File.Create(file);
}
}
The classes in System.IO should help you do that.
FileStream fs = System.IO.File.Create(fileName);