---
title: "common dialog"
type: "forum-thread"
url: "https://www.webforum.nu/amne/dotnet/43819-common-dialog"
topic: ".NET"
topic_url: "https://www.webforum.nu/amne/dotnet"
author: "OveRRidE"
published: "2002-05-15T13:09:34.000Z"
updated: "2002-05-15T15:04:36.000Z"
replies: 2
views: 214
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/dotnet/43819-common-dialog"
---

# common dialog

## #1 — OveRRidE, 2002-05-15T13:09Z

Jag försöker få min common dialog control att fungera utan att behöva välja en fil. 

Jag vill med andra ord kunna välja enbart en mapp och inte en specifik fil. Det verkar dock inte gå.. nån som vet hur man gör med t.ex. API för att komma runt detta?

Permalänk: https://www.webforum.nu/p/43819

## #2 — Jon, 2002-05-15T15:01Z

Jag vet att det går. Har gjort det med API. Tyvärr har jag inte koden här men jag kan kolla upp det imorron om ingen har svarat eller om du inte kommit på det tills då :)

Har för mig att jag hittade det på nån av de stora VB-siterna på nätet...

Permalänk: https://www.webforum.nu/p/673745

## #3 — OveRRidE, 2002-05-15T15:04Z

Jag löste det. 

**I modulen**

```
Option Explicit
Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
        "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
        "SHGetPathFromIDListA" (ByVal pidl As Long, _
        ByVal pszPath As String) As Long

Const BIF_RETURNONLYFSDIRS = &H1

Type BROWSEINFO
   hOwner As Long
   pidlRoot As Long
   pszDisplayName  As String
   lpszTitle As String
   ulFlags As Long
   lpfn As Long
   lParam As Long
   iImage As Long
End Type

Type SHITEMID
   cb As Long
   abID As Byte
End Type

Type ITEMIDLIST
   mkid As SHITEMID
End Type
```

**I forumläret**

```
Dim bi As BROWSEINFO
Dim IDL As ITEMIDLIST
Dim r As Long
Dim pidl As Long
Dim tmpPath As String
Dim pos As Integer
'Egen lösning, då jag har option explicit i toppen
'Const BIF_RETURNONLYFSDIRS = 1

Function GetBrowseDirectory(Owner As Form) As String
   bi.hOwner = Owner.hWnd
   bi.pidlRoot = 0&
   bi.lpszTitle = "Välj en mapp från listan:"
   bi.ulFlags = BIF_RETURNONLYFSDIRS
   pidl = SHBrowseForFolder(bi)

   tmpPath = Space$(512)
   r = SHGetPathFromIDList(ByVal pidl, ByVal tmpPath)

   If r Then
      pos = InStr(tmpPath, Chr$(0))
      tmpPath = Left(tmpPath, pos - 1)

      If Right(tmpPath, 1) <> "\" Then tmpPath = tmpPath & "\"
         GetBrowseDirectory = tmpPath
      Else
         GetBrowseDirectory = ""
      End If

End Function
```

**Anropas med**

```
txtSokvag.Text = GetBrowseDirectory(frmStart)
```

Permalänk: https://www.webforum.nu/p/673746

---

Tråden på webben: https://www.webforum.nu/amne/dotnet/43819-common-dialog
