Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
public static void Create(string path)
{
if (String.IsNullOrEmpty(path))
{
throw new ArgumentException("Path cannot be an empty string.");
}
int startPos = 1; // First part of the path to create.
// Split the given string into components which will have to be individually created.
String[] pathComponents = path.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
// Get the first path component, either "c:" or "\\servername".
String partPath = pathComponents[0];
// If the path is a UNC path, then add the share to the initial starting path.
if (partPath.StartsWith(@"\\"))
{
if (pathComponents.Length < 3)
{
throw new ArgumentException("Invalid path specified: " + path);
}
// If the path is the root of a drive, then add the directoy separator char.
if (partPath.Contains(":"))
{
if (pathComponents.Length < 2)
{
throw new ArgumentException("Invalid path specified: " + path);
}
// Add the directory separator char here since Path.Combine will not add it if a drive specifier (ie: "C:") is given.
// See Remarks in http://msdn.microsoft.com/en-us/library/fyy7a5kt.aspx
// Also see http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#relative%5Fpaths
partPath += Path.DirectorySeparatorChar;
}
// Create the individual path components.
for (int i = startPos; i < pathComponents.Length; i++)
{
// Add the path component to create.
partPath = System.IO.Path.Combine(partPath, pathComponents[i]);
// Create the path.
if (!NativeMethods.CreateDirectory(normalizedPath, IntPtr.Zero))
{
// To mimic Directory.CreateDirectory, we don't throw if the directory (not a file) already exists
int errorCode = Marshal.GetLastWin32Error();
if (errorCode != NativeMethods.ERROR_ALREADY_EXISTS || !LongPathDirectory.Exists(partPath))
{
throw LongPathCommon.GetExceptionFromWin32Error(errorCode);
}
}
}
}
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).