Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I wann to create runtime directory in root folder. By this code
string strDate = DateTime.Now.ToString("d-M-yyh:mm:ss.ffftt").ToString();
Directory.CreateDirectory(Server.MapPath("~/Images/Work/") + ddl_category.SelectedItem.Text).CreateSubdirectory(strDate);

But i am getting some error. so please me, How to Create directory with its sub folder at runtime.
Posted
Comments
What is that error?

Hi if you want to create directory from server be sure your asp.net user have a access permissions on this directory you can check it by right click on root directory and check the security tab or you do it with IIS or your target web server facilities and after that you can see follow of links how to create directory at run time with code :

http://www.beansoftware.com/ASP.NET-FAQ/Make-Directory.aspx[^]

http://www.aspnettutorials.com/tutorials/file/file-dir-aspnet2-vb/[^]
http://www.venkateswarlu.co.in/DotNet/creat_delete_folder.aspx[^]
http://stackoverflow.com/questions/17092282/asp-net-create-folder-and-file-in-other-server[^]

Best Regards
 
Share this answer
 
The problem is you are trying to create a directory that contains ':' characters. Here:
C#
string strDate = DateTime.Now.ToString("d-M-yyh:mm:ss.ffftt").ToString();

That is not possible.
You should rethink the naming scheme for one that is compatible with NTFS filesystem.

Please see NTFS Naming Conventions[^]

(Moreover, why do you call ToString() method twice? Don't you trust the first call to return a string value?)
 
Share this answer
 
v2

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