当我用Path.GetTempFileName()函数去取一个目录名时,竟然得到这样的结果:C:\DOCUME~1\Vitami~1。。。应该是c:\Documents and Settings\VitaminC.net的。找了半天,最后在GotDotNet找到了结果,把代码贴出来大家看看:

.net里长短文件名的解决办法using System;
.net里长短文件名的解决办法
using
 System.Text;
.net里长短文件名的解决办法
using
 System.Runtime.InteropServices;
.net里长短文件名的解决办法
.net里长短文件名的解决办法
namespace
 ShellPathNameConvert

运行结果:
Current directory:
D:\Documents and Settings\Administrator\桌面\ShellPathNameConvert\ShellPathNameC
onvertTest\bin\Debug

Short path name:
D:\DOCUME~1\ADMINI~1\桌面\SHELLP~1\SHELLP~2\bin\Debug

Long path name:
D:\Documents and Settings\Administrator\桌面\ShellPathNameConvert\ShellPathNameC
onvertTest\bin\Debug

说明:
ShellPathNameConvert will allow you to convert to and from Long and Short paths. It's common for the Windows shell to send you a short path if your application takes command line arguments. However, it's not always convenient to work with the short path names and .NET provides no built in way to get the long path nam

相关文章: