Saturday, May 30, 2009

Short/Long path conversion

// Short/Long path conversion

// Long To Short Path/File Name:

[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(1024);
GetShortPathName(textBoxFilename.Text, shortPath, shortPath.Capacity);



// Short To Long Path/File Names:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetLongPathName(
[MarshalAs(UnmanagedType.LPTStr)]
string path,
[MarshalAs(UnmanagedType.LPTStr)]
StringBuilder longPath,
int longPathLength
);

2 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. If you get any issues related to long path files, you must use long path tool, it works good.

    ReplyDelete