Private Structure BrowseInfo
Public hWndOwner As IntPtr
Public pidlRoot As Integer
Public sDisplayName As String
Public sTitle As String
Public ulFlags As Integer
Public lpfn As Integer
Public lParam As Integer
Public iImage As Integer
End Structure
Private Const BIF_RETURNONLYFSDIRS As Short = &H1S
Private Const BIF_DONTGOBELOWDOMAIN As Short = &H2S
Private Const BIF_STATUSTEXT As Short = &H4S
Private Const BIF_RETURNFSANCESTORS As Short = &H8S
Private Const BIF_BROWSEFORCOMPUTER As Short = &H1000S
Private Const BIF_BROWSEFORPRINTER As Short = &H2000S
Private Const MAX_PATH As Short = 256
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal nPidl As Integer, ByVal pszPath As String) As Integer
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (ByRef lpBrowseInfo As BrowseInfo) As Integer
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal PV_Renamed As Integer)
' Let the user browse for a folder.
' Return the folder or Nothing if the user cancels.
Public Function BrowseForFolder(ByRef dialog_title As String) As String
Try
Dim browse_info As BrowseInfo
With browse_info
.pidlRoot = 0
.sDisplayName = Space$(260)
.sTitle = dialog_title
.ulFlags = BIF_RETURNONLYFSDIRS
.lpfn = 0
.lParam = 0
.iImage = 0
End With
Dim item As Integer = SHBrowseForFolder(browse_info)
Dim path As String = New String(" "c, MAX_PATH)
If SHGetPathFromIDList(item, path) = 0 Then
path = Nothing
Else
path = path.Trim
End If
CoTaskMemFree(item)
Return path
Catch ex As Exception
Return Nothing
End Try
End Function
'Här skapar jag en knapp som öppnar själva fönstret där du kan välja katalog och sökvägen hamnar i new_folder strängen.
'Observera att du på aspx filen måste skapa en knapp som har variabeln Knapp
Private Sub Knapp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Knapp.Click
Dim new_folder As String = BrowseForFolder("Select Folder")
End Sub