Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
HI FRIENDS...
I want to create a folder named with the current time, and it comes me an exception see the code below
string data = DateTime.Now.Year.ToString() + ":" + DateTime.Now.Month.ToString() + ":" + DateTime.Now.Date.ToString() + ":" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
string path = @"C:\www\" + data;
DirectoryInfo dr = new DirectoryInfo(path);
dr.Create();


thank you friends
Posted
Updated 30-Apr-11 1:41am
v2
Comments
Abdul Rahman Hamidy 30-Apr-11 7:12am    
what is the exception you are getting and i think you are using illegal characters in folder name.

I agree with Abdul - the ":" in folder name is almost certainly not allowed - try "-" instead.
 
Share this answer
 
replace ':' with '#' in creation mode...
when you retrive the file you can replace '#' with ':' using String.replace
 
Share this answer
 
Hi,

Please try this

string data = DateTime.Now.ToString("yyyyMMddHHmmss");

or
string data = DateTime.Now.ToString("yyyy-MM-dd#HH-mm-ss");


instead of your expression.

Regards
AR
 
Share this answer
 
v3
Comments
guendouz bachir 30-Apr-11 7:45am    
this code work perfectly, i think that i have used illegal characters in folder name, thank you for all
Kim Togo 30-Apr-11 7:53am    
Remember to press "Accept Answer" :-)
guendouz bachir 30-Apr-11 11:52am    
i have do it thx

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