PathCompactPath??

Data Danger

Active member
Joined
Mar 25, 2004
Messages
29
Can somebody tell me if there is another way to compact long path names without using the shlwapi.dll file PathCompactPath command or should I still use it in .net. Thanks
 
I really dont have a clue about what that does but if you give me a practical example of what and why youre trying to do then I might help.

Alex :p
 
What it does

If you want to display a path name like C:\Documents and Settings\User Name\Programs\FileName.xxx but you only have a certain amount of space to show it in you can use PathCompactPath and it will return a compacted path like C:\...\Filename.xxx. I use this because in my program I display in my drop down menu the last 4 recent projects, if I display the whole path then the width of the menu gets to wide, by using PathCompactPath I can reduce the filename down to a requested length. Hope this helps.
 
The only possibility I can see is to build your own control...
Maybe inherit from the label control or the link control and add that functionality...

Its not that hard... the Sistem.IO have some methods to help with that!

Alex :p
 
Data Danger said:
Can somebody tell me if there is another way to compact long path names without using the shlwapi.dll file PathCompactPath command or should I still use it in .net. Thanks

something along these lines should do the trick.
Load instances of this class into your list

may have errors, but you will get the idea
PHP:
public class FileNameString: string
{
int maxDisplayLength = 60;
 
public string DisplayValue
{
get
{
	string temp = this;
	if (this.length() > maxDisplayLength)
	{
	 if (System.IO.Path.IsPathRooted(temp))
	 temp = temp.SubString(0,1) + 
	 String.format( "{0}{1}...{1}{2}", 
			 System.IO.Path.VolumeSeparatorChar,
			 System.IO.Path.PathSeparator, temp)+ 
			 System.IO.Path.GetFileName(temp);
	 else
	 {
	 int i = temp.IndexOf(String.Format("{0}{0}", System.IO.Path.VolumeSeparatorChar));
	 if (i==0)
	 temp = temp.Substring(0,temp.IndexOf(2,Format("{0}", System.IO.Path.VolumeSeparatorChar),2)) +
			 String.format( "{0}...{0}", 
			 System.IO.Path.PathSeparator) + 
			 System.IO.Path.GetFileName(temp);
	 }
	}
	return temp;
}
}
public string ValueMember
{
get
{
	return this;
}
}
 
public int MaxDisplayLength 
{
get
{
	return maxDisplayLength;
}
set
{
	maxDisplayLength = value;
}
}
public FileNameString(string s, int n):base()
{
	 this = s;
	 maxDisplayLength = n;	 
}
 
public FileNameString(string s):base()
{
	 this = s;
}
 
}
Set your lists DisplayMember = "DisplayMember"
and ValueMember = "ValueMember"

given an ArrayList of strings sa

doing this should work

PHP:
MyList.DisplayMember = "DisplayMember";
MyList.ValueMember = "ValueMember";
for (int i = 0; i < sa.Count; i++)
MyList.Add(new FileNameString(sa[i].ToString(), 25)
 
Back
Top