Short display for long filenames

  • Thread starter Thread starter Daniel Bolege
  • Start date Start date
D

Daniel Bolege

Hello,

as most of you know, some programs that handle files have a "recent files"
feature, that is mostly a menu item within the file menu that shows the
last documents the user had opened. Visual studio .net gives you an
example.

This example shows as well that long filenames will be displayed shortened
to fit the menu item, e.g.

C:\Documents and settings\John Doe\My files\XYZ\document.xyz

might be displayed as

C:\Documents and settings\ ... \XYZ\document.xyz

As I would like to have this feature in my own brilliant and amazing
helloWorld-application, too, I'm wondering if there isn't a function in
the .net framework that returns the shorter version of a full path that
exceeds a specified length.

Of course, it is possible - actually for me - to parse the string for
myself, but I would not like to reinvent the wheel.

Just to prevent misunderstandings: I don't mean that kind of short filenames
returned by the GetShortPathName-API-function like "C:\Documn~1\John~1" ...

So: Did I overlook something in the .net documentation?

Regards Daniel
 
Daniel,

There's nothing like that in the framework as far as I know. But the
native API PathCompactPath[Ex] does what you want.



Mattias
 
Hi Mattias
There's nothing like that in the framework as far as I know. But the
native API PathCompactPath[Ex] does what you want.

Thanks for your answer. Seems there's a lot of stuff provided by the win api
what is currently not integrated in the .net framework.

BTW, the PathCompactPath does not works so nice as it is mentioned in my
examples. The left part is always cut without paying attention to the
directory structure, e.g:

C:\Documents and settings\John Doe\My files\XYZ\document.xyz

might be tailored to

C:\Documents and settings\Jo...\XYZ\document.xyz

where a better, more readable way would be

C:\Documents and settings\ ... \XYZ\document.xyz

Well, just peanuts and reserved for a newer version.

Daniel
 
Back
Top