truncate file path
Published: 27. January 2009 | Updated: 26. September 2011License: Microsoft Public License (MS-PL)
Categories: File system, Windows » Win32
Tags: C# File System Win32 Windows
Import namespaces
using System.Runtime.InteropServices; using System.Text;
Win API
[DllImport("shlwapi.dll", CharSet = CharSet.Auto)] static extern bool PathCompactPathEx([Out] StringBuilder pszOut, string szPath, int cchMax, int dwFlags);
Use
string path = @"C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft .NET Framework 3.5 SP1\test.dll"; StringBuilder sb = new StringBuilder(); int length = 40; // truncate path PathCompactPathEx(sb, path, length, 0); Console.WriteLine(sb);Console Output:
C:\WINDOWS\Microsoft.NET\Fr...\test.dll
| Send us feedback about this snippet » |





