Lifestyle, hobbies, work, rage…
Unicode to DOS Filenames
DOS is a pain. .NET doesn’t get along too well with DOS either, since everything .NET is Unicode – just like everything, actually.
How to change from Unicode (aka, Kanji characters) to DOS Filenames:
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern uint GetShortPathName([MarshalAs(UnmanagedType.LPTStr)] string lpszLongPath, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszShortPath, uint cchBuffer);
public static string ToDOSPathName(String longName) {
StringBuilder shortNameBuffer = new StringBuilder(256);
uint bufferSize = (uint)shortNameBuffer.Capacity;
uint result = GetShortPathName(longName, shortNameBuffer, bufferSize);
return shortNameBuffer.ToString();
}
| Print article | This entry was posted by Boris on January 26, 2008 at 4:21 pm, and is filed under C#, Programming. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |