GetShortPathName (kernel32)
Last changed: -74.13.52.113

.
Summary
Retrieves the short path form of the specified path.

C# Signature:

[DllImport("kernel32.dll", SetLastError=true, CharSet=CharSet.Auto)]
static extern int GetShortPathName(
    string lpszLongPath,
    [Out] StringBuilder lpszShortPath,
    int cchBuffer);

User-Defined Types:

None.

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

/// <summary>
/// The ToLongPathNameToShortPathName function retrieves the short path form of a specified long input path
/// </summary>
/// <param name="longName">The long name path</param>
/// <returns>A short name path string</returns>
public static string ToShortPathName(string longName)
{
    StringBuilder shortNameBuffer = new StringBuilder();

    int size = GetShortPathName(longName, shortNameBuffer, shortNameBuffer.Capacity);
    if(size >= shortNameBuffer.Capacity)
    {
        shortNameBuffer.Capacity = size + 1;
        GetShortPathName(longName, shortNameBuffer, shortNameBuffer.Capacity);
    }

    return shortNameBuffer.ToString();
}

Alternative Managed API:

Do you know one? Please contribute it!

Documentation