using System.IO;

Does directory exist?

(Note paths can include a filename if you wish)


	if (!Directory.Exists(Path.GetDirectoryName(MyFileName)))
		Directory.CreateDirectory(Path.GetDirectoryName(MyFileName));
	//or
	String path;
	path = "C:\\Atest\\";				//		'\\'='\'
	if (!Directory.Exists(path))
	//or
	if (!Directory.Exists("C:\\Atest\\"))	//		'\\'='\'

Create Directory

(Note paths can include a filename if you wish)


	Directory.CreateDirectory(Path.GetDirectoryName(MyFileName));
	//or
	String path;
	path = "C:\\Atest\\";				//		'\\'='\'
	Directory.CreateDirectory(path);
	//or
	Directory.CreateDirectory("C:\\Atest\\");	//		'\\'='\'

Get Directory From File Path


	sTemp = Path.GetDirectoryName(MyFilename)

 

USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.