短文件名(经常用到)

public static string ToShortPathName(string longName)
  {
   StringBuilder shortNameBuffer = new StringBuilder(256);
   int bufferSize = shortNameBuffer.Capacity;

   int result = GetShortPathName(longName, shortNameBuffer, bufferSize);

   return shortNameBuffer.ToString();
  }
  [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
  public static extern int GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string path,[MarshalAs(UnmanagedType.LPTStr)] StringBuilder shortPath,int shortPathLength);
 

你可能感兴趣的:(c#)