GetLongPathName (kernel32)
Last changed: -137.48.131.236

.
Summary
Converts the specified path to its long form.

C# Signature:

using System.Runtime.InteropServices;
using System.Text;

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

User-Defined Types:

None.

Notes:

The GetLongPathName API call is only available on Windows 98/ME and Windows 2000/XP. It is not available on Windows 95 & NT.

The file must exist to get the correct path. This is because the full path comes from the file system information. If an invalid name is given and exception is not thrown rather the name is just a blank space.

Tips & Tricks:

Please add some!

Sample Code:

/// <summary>
/// The ToLongPathName function retrieves the long path form of a specified short input path
/// </summary>
/// <param name="shortName">The short name path</param>
/// <returns>A long name path string</returns>
public static string ToLongPathName(string shortName)
{
    StringBuilder longNameBuffer = new StringBuilder(256);
    uint bufferSize = (uint)longNameBuffer.Capacity;

    GetLongPathName(shortName, longNameBuffer, bufferSize);

    return longNameBuffer.ToString();
}

Alternative Managed API:

/// <summary>
/// The ToLongName function retrieves the long file name form of a specified short input path
/// </summary>
/// <param name="shortName">The short name path</param>
/// <returns>A long file name string</returns>
public static string ToLongName(string shortName)
{
    string[] paths = Directory.GetFiles( Path.GetDirectoryName(shortName), Path.GetFileName(shortName) );

    return Path.GetFileNameWithoutExtension( paths[0] );
}

Documentation