Global Travel-盛开的夕阳,走向家的方向

c/c++/c#/.net/ajax/英文技术文章/系统架构/项目管理

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
原文:http://topic.csdn.net/t/20050329/13/3890750.html
该方法在对写入C盘的路径(特别是桌面)之类的长路径进行转换,避免出现路径自动被截取出现错误

using   System.Runtime.InteropServices;  
   
  定义:  
  [DllImport("kernel32.dll",   CharSet   =   CharSet.Auto)]  
  public   static   extern   int   GetShortPathName(  
  [MarshalAs(UnmanagedType.LPTStr)]  
  string   path,  
  [MarshalAs(UnmanagedType.LPTStr)]  
  StringBuilder   shortPath,  
  int   shortPathLength);  
   
  引用:  
  StringBuilder   shortPath   =   new   StringBuilder(80);  
  int   result   =   GetShortPathName(  
  @"F:\1234567891.jpg",   shortPath,   shortPath.Capacity);  
  string   s   =   shortPath.ToString();  
  MessageBox.Show(s.ToString());  
   
  结果:  
  F:\123456~1.jpg
posted on 2006-07-25 08:28  Seraph's Zone(WelCome)  阅读(864)  评论(0编辑  收藏  举报