Click here to Skip to main content
15,922,145 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello Friends,

I am creating a windows application in which i need to move a xml file from one directory to another.
Problem is that i want to move the file into a new directory which will be created according to the date of its moving,means if the file is been moved today then the file will be stored in MovedFolder/2012/March/15/FileName.xml.

Thanks in advance

Have you tried the very obviously named Directory.CreateDirectory[^]
Share this answer
#realJSOP 15-Mar-12 7:47am    
DAMMIT! That was a secret, locked away in the vast hidden information vaults at google!
RashdSiddique 15-Mar-12 7:50am    
yes but it will only create a single directory,but i want a nested subdirectories and according to current date
#realJSOP 15-Mar-12 7:58am    
You have to create new directories one at a time. There's no magic solution for you. I know this might traumatize you, but you're going to have to actually have to write code.
CreateDirectory can create a sequence of subdirectories

will create all three directories if they don't already exist.

A little bit of custom DateTime formatting will get you what you want. [^]


[EDIT] sorry that was complete nonsense, this will work:

private static void CreateDirectories() {
  DateTime current = DateTime.Now;
  String name = String.Format(@"v:\{0:yyyy}\{1:MMMM}\{2:dd}", current, current, current);
  try {
  } catch (Exception e) {

Share this answer
ProEnggSoft 15-Mar-12 20:09pm    
Good solution. 5ed!

hope this will help....

string path = "D:\\MoveFolder\\" + DateTime.Now.Year.ToString() + "\\" +
DateTime.Now.ToString("MMMM") + "\\" + DateTime.Now.Day.ToString();

FileStream fs = File.Create(path+"\\Filename.xml");
Share this answer

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