NOMBRE CORTO DE RUTA (C#)


 //Short Path Name -->
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern uint GetShortPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string lpszLongPath,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder lpszShortPath,
uint cchBuffer);


[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
       static extern uint GetShortPathName(string lpszLongPath, char[] lpszShortPath, int cchBuffer);
// <-- Short Path Name



 public string ToShortPathName(string longName)
{
    uint bufferSize = 256;
    StringBuilder shortNameBuffer = new StringBuilder((int)bufferSize);
    uint result = GetShortPathName(longName, shortNameBuffer, bufferSize);
    return shortNameBuffer.ToString();
}


public string ShortPath(string longpath)
{
    char[] buffer = new char[256];
    GetShortPathName(longpath, buffer, buffer.Length);
    return new string(buffer);
}

1 comentario: