System.IO.Path.GetTempFileName returns "8.3"-style names

  • Thread starter Thread starter Dmitry Shaporenkov
  • Start date Start date
D

Dmitry Shaporenkov

Hi all,

does anybody know is there any way to get Windows-style
long name from "8.3"-style name returned by
System.IO.Path.GetTempFileName ()? I.e., I would like to
get

C:\Documents and Setting\user\Local Settings\

instead of

C:\Docume~1\user\Locals~1.

I need a long name to pass it to the external program
which only accepts long names.
Does .NET framework provide a function for performing
such conversions? Or, if not, how can I convert names
using P/Invoke or smth else?

Thanks in advance,
Dmitry
 
Hi,

You will have to resort to using P/Invoke to GetLongPathName in
kernel32.dll. From the MSDN this in not available on NT4 or 95, so but I
recall that there was something in the MSDN indicating that you can use
FindFirstFile on each component of the path to build the long filename.

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern int GetLongPathName( string shortPath, StringBuilder longPath,
int bufferSize );

Remember to set the capacity for the StringBuilder before calling this
function.

Hope this helps

Chris Taylor
 
Chris, thanks for your response. I've found
code that seems to do the trick:

string[] elm = shortPath.Split(
new char[] { Path.DirectorySeparatorChar,
Path.AltDirectorySeparatorChar} );
string lpath = elm[0] +
Path.DirectorySeparatorChar;
for( int p = 1; p < elm.Length; p++ )
{
string[] npath =
Directory.GetFileSystemEntries( lpath, elm[p] );
lpath = npath[0];
}
return lpath;
-----Original Message-----
Hi,

You will have to resort to using P/Invoke to GetLongPathName in
kernel32.dll. From the MSDN this in not available on NT4 or 95, so but I
recall that there was something in the MSDN indicating that you can use
FindFirstFile on each component of the path to build the long filename.

[DllImport("kernel32.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern int GetLongPathName( string shortPath, StringBuilder longPath,
int bufferSize );

Remember to set the capacity for the StringBuilder before calling this
function.

Hope this helps

Chris Taylor


"Dmitry Shaporenkov"
Hi all,

does anybody know is there any way to get Windows-style
long name from "8.3"-style name returned by
System.IO.Path.GetTempFileName ()? I.e., I would like to
get

C:\Documents and Setting\user\Local Settings\

instead of

C:\Docume~1\user\Locals~1.

I need a long name to pass it to the external program
which only accepts long names.
Does .NET framework provide a function for performing
such conversions? Or, if not, how can I convert names
using P/Invoke or smth else?

Thanks in advance,
Dmitry


.
 
Back
Top