.NET 4.x Как преобразовать длинный путь к файлу в короткий - Visual Basic .NET
Формулировка задачи:
Подскажите пример, пробовал так, не получается:
Это я на просторах интернета находил )
Решение задачи: «.NET 4.x Как преобразовать длинный путь к файлу в короткий»
textual
Листинг программы
Public Class Form1
Declare Unicode Function GetShortPathName Lib "kernel32.dll" Alias "GetShortPathNameW" ( _
ByVal longPath As String, _
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> _
ByVal ShortPath As System.Text.StringBuilder, _
<System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.U4)> _
ByVal bufferSize As Integer) As Integer
Function ShortPathName(ByVal Path As String) As String
Dim sb As New System.Text.StringBuilder(1024)
Dim tempVal As Integer = GetShortPathName(Path, sb, 1024)
If tempVal <> 0 Then
Dim Result As String = sb.ToString()
Return Result
Else
Throw New Exception("Failed to return a short path")
End If
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
MsgBox(ShortPathName(Application.StartupPath))
End Sub
End Class