Código fuente en el form
Option Explicit On
Imports System.Collections
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles Button1.Click
Try
' Configuración del FolderBrowserDialog
With FolderBrowserDialog1
.Reset() ' resetea
' leyenda
.Description = " Seleccionar una carpeta "
' Path " Mis documentos "
.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
' deshabilita el botón " crear nueva carpeta "
.ShowNewFolderButton = False
'.RootFolder = Environment.SpecialFolder.Desktop
'.RootFolder = Environment.SpecialFolder.StartMenu
Dim ret As DialogResult = .ShowDialog ' abre el diálogo
' si se presionó el botón aceptar ...
If ret = Windows.Forms.DialogResult.OK Then
Dim nFiles As ObjectModel.ReadOnlyCollection(Of String)
nFiles = My.Computer.FileSystem.GetFiles(.SelectedPath)
MsgBox("Total de archivos: " & CStr(nFiles.Count),MsgBoxStyle.Information)
End If
.Dispose()
End With
Catch oe As Exception
MsgBox(oe.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Button1.Text = "Abrir"
End Sub
End Class
Imports System.Collections
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles Button1.Click
Try
' Configuración del FolderBrowserDialog
With FolderBrowserDialog1
.Reset() ' resetea
' leyenda
.Description = " Seleccionar una carpeta "
' Path " Mis documentos "
.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
' deshabilita el botón " crear nueva carpeta "
.ShowNewFolderButton = False
'.RootFolder = Environment.SpecialFolder.Desktop
'.RootFolder = Environment.SpecialFolder.StartMenu
Dim ret As DialogResult = .ShowDialog ' abre el diálogo
' si se presionó el botón aceptar ...
If ret = Windows.Forms.DialogResult.OK Then
Dim nFiles As ObjectModel.ReadOnlyCollection(Of String)
nFiles = My.Computer.FileSystem.GetFiles(.SelectedPath)
MsgBox("Total de archivos: " & CStr(nFiles.Count),MsgBoxStyle.Information)
End If
.Dispose()
End With
Catch oe As Exception
MsgBox(oe.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Button1.Text = "Abrir"
End Sub
End Class
Este otro ejemplo establece en la propiedad rootFolder, la ruta de nivel
superior del árbol de carpetas ( escritorio, la carpeta inicio, mis documentos,
favoritos, mi pc etc.. ) en este caso la carpeta Inicio
Option Explicit On
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles Button1.Click
Try
' Configuración del FolderBrowserDialog
With FolderBrowserDialog1
.RootFolder = Environment.SpecialFolder.StartMenu
Dim ret As DialogResult = .ShowDialog ' abre el diálogo
' si se presionó el botón aceptar ...
If ret = Windows.Forms.DialogResult.OK Then
MsgBox("Path : " & .SelectedPath, MsgBoxStyle.Information)
End If
.Dispose()
End With
Catch oe As Exception
MsgBox(oe.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles MyBase.Load
Button1.Text = "Abrir"
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles Button1.Click
Try
' Configuración del FolderBrowserDialog
With FolderBrowserDialog1
.RootFolder = Environment.SpecialFolder.StartMenu
Dim ret As DialogResult = .ShowDialog ' abre el diálogo
' si se presionó el botón aceptar ...
If ret = Windows.Forms.DialogResult.OK Then
MsgBox("Path : " & .SelectedPath, MsgBoxStyle.Information)
End If
.Dispose()
End With
Catch oe As Exception
MsgBox(oe.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) _
Handles MyBase.Load
Button1.Text = "Abrir"
End Sub
End Class
No hay comentarios:
Publicar un comentario