[vb.net] OpenFileDialog Example > vb.net

본문 바로가기

vb.net

[Controls] [vb.net] OpenFileDialog Example

회원사진
하나를하더라도최선을
2023-06-21 15:20 1,349 0

본문



        Dim ofd As New OpenFileDialog()
        '// ofd.FileName = "default.매뉴"    '// 최초지정 파일
        '// ofd.InitialDirectory = "C:\"    '// 처음에 표시되는 폴더(미지정시 현재폴더)
        ofd.Filter = "All file(*.*)|*.*"    '// 파일종류(미지정시 모든파일)
        ofd.FilterIndex = 1    '// 처음에는 모든 파일이 선택되도록 지정
        ofd.Title = "file Select"    '// 타이틀
        ofd.RestoreDirectory = True    '// 다이얼로그박스 닫기젖 현재의 디렉토리를 복원
        ofd.CheckFileExists = True    '// 존재하지 않는 파일 지정시 경고(자동지정)
        ofd.CheckPathExists = True    '// 존재하지 않는 폴더 지정시 경고(자동지정)
        ofd.Multiselect = True          '// 여러파일 선택가능
        If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Dim fileName As String, extension As String
            Dim nm As String = sender.Name
            Dim first As Integer = nm.Split("_").Last
            Dim idx As Integer = nm.Split("_")(1)
            Dim hundredth As Integer = idx : hundredth *= 100
            Dim thousand As Integer = Me.Name.Split("_"c).Last : thousand *= 1000
            thousand += hundredth + first
            Dim R As DataRow, F() As DataRow, LB As Label
            For Each filePath As String In ofd.FileNames
                F = fileData.Select(String.Format("[path]='{0}'", filePath))
                If F.Length > 0 Then Continue For
                R = fileData.NewRow
                R("idx"= idx
                R("file_id"= thousand
                R("path"= filePath
                fileName = System.IO.Path.GetFileNameWithoutExtension(filePath) '// filePath.Split({"/", "\", "//"}).Last()
                extension = System.IO.Path.GetExtension(filePath).Substring(1)
                R("name"= fileName
                R("extension"= extension
                fileData.Rows.Add(R)
 
            Next
            DirectCast(sender, Custom.Controls.BHSButton).TextColor = Color.FromArgb(2551518376)
        End If

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색