0320 Convert Long to Short File Names in C#
这样也能上头条?
too simple, too young, too native!
Convert Long to Short File Names in C#
By Rajesh Charagandla March 17, 2006
Here in this article is very simple code for short to long and long to short file names conversion.
Technologies: .NET Framework,Visual C# .NET
Total downloads :
Total page views : 349
Rating : 0/5 This article has been rated : 0 times
Advertise here
Hello. Here is very simple code for short to long and long to short file names conversion.
Short to long:
using System;
using System.Runtime.InteropServices;
using System.Text;
public class _Main
&leftsign;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetLongPathName( [MarshalAs(UnmanagedType.LPTStr)] string path,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder longPath, int longPathLength );
public static void Main()
&leftsign;
StringBuilder longPath = new StringBuilder(255);
GetLongPathName(@"D:\\MYTEMP~1\\RESOUR~1\\sql.txt", longPath, longPath.Capacity);
Console.WriteLine(longPath.ToString());
&rightsign;
&rightsign;
Long to short:
using System;
using System.Runtime.InteropServices;
using System.Text;
public class _Main
&leftsign;
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName( [MarshalAs(UnmanagedType.LPTStr)] string path, MarshalAs(UnmanagedType.LPTStr)]
StringBuilder shortPath, int shortPathLength );
public static void Main()
&leftsign;
StringBuilder shortPath = new StringBuilder(255);
GetShortPathName(@"D:\\My Temp\\ResourseProvider\\sql.txt", shortPath, shortPath.Capacity);
Console.WriteLine(shortPath.ToString());
&rightsign;
&rightsign;
Please note that file must exists on the disk. This occur because file system need to know if other files. Two long names produce same names in short form and if so file system will add unique indexes to them.
历史博文
- 20081125 内存 优化 - 2009
- 20071024 uclinux java jikes kaffe - 2008
- 20070225 boblog 备份 插件 update - 2007
- VB资源文件多语言版本 - 2005
- µC/OS-II UCOSII学习笔记5 - 2005
- µC/OS-II UCOSII学习笔记4 - 2005