I need to create a file with a name of IP address:
The code is:

string dirAddress = "C:\\FTPTrace\\" + ipHeader.DestinationAddress.ToString() + ".txt";
System.IO.StreamWriter logfile = new StreamWriter(dirAddress,true);

It works fine.. But i also want to include current date in the file name...
The code is :

string dirAddress = "C:\\FTPTrace\\" + ipHeader.DestinationAddress.ToString() + DateTime.Now.ToShortDateString().ToString()+ ".txt";

System.IO.StreamWriter logfile = new System.IO.StreamWriter(dirAddress, true);

Now the file is not being created , an exception is raised

"A first chance exception of type 'System.IO.DirectoryNotFoundException' occurred in mscorlib.dll"

Kindly guide where am I wrong.... thanks...

this error because when you use this

DateTime.Now.ToShortDateString().ToString()

it gives following output and with the slashes(/) 2/15/2012
so insted of try this to solve a problem or

DateTime.Now.ToShortDateString().ToString().Replace("/","")
DateTime.Now.ToShortDateString().ToString().Replace("/","-")
DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Date.ToString()

You don't have to use DateTime.Now.ToShortDateString().ToString(); use DateTime.Now.ToShortDateString();
And for your problem use : DateTime.Now.ToString("dd-MM-yyyy");

Comments
Excellent, to-the-point advice.
This question has already been answered. Start a new discussion instead.