I just can't get around this. I am able to create a file with File.Create ... File..Text and so on, only if the path exists. If it does not the file will not we write and return an error. How do I create a path?
As this post mostlikely solves your problem here the additional MSDN information: http://msdn.microsoft.com/en-us/library/as2f1fez.aspx
Bdiem
2009-08-24 08:41:18
And how do we check if the path exists? or we just call this function.
Jonathan Shepherd
2009-08-24 08:46:14
READ! MSDN Says: If the folder already exists, CreateDirectory does nothing.
Bdiem
2009-08-24 08:48:00
+3
A:
You will need to create the Directory first. It will create all of the subdirectories that don't exist within the path you send it. It's quite a powerful piece of functionality.
Directory.CreateDirectory(filePath);
If you don't know whether the directory exists or not you can use Directory.Exists. But not for this case as it would be pointless. MSDN states that CreateDirectory does nothing if the directory currently exists. But if you wanted to check existance of the directory for another reason you can use:
if(Directory.Exists(folder) == false)
{
//do stuff
}
ThePower
2009-08-24 08:39:24