Reputation: 41
string path1 = @"C:\temp\";
string path2 = "";
// Create directory temp if it doesn't exist
if (!Directory.Exists(path1))
{
Directory.CreateDirectory(path1);
}
I created the above directory temp
, but i don't konw how to create subdirectory (like temp1
) in temp
?
Upvotes: 3
Views: 10395
Reputation: 148980
You've got the basic code already, you just need to tweak it a bit. According to the documentation on CreateDirectory
Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid.
So you can just specify the full path to temp1
and use one call.
string path1 = @"C:\temp\";
string path2 = Path.Combine(path1, "temp1");
// Create directory temp1 if it doesn't exist
Directory.CreateDirectory(path2);
Note that this applies any time you want to create a directory. There's nothing special about doing this in a WPF application.
Upvotes: 10