Using the open file and save file dialogs in vb.net

后端 未结 3 909
伪装坚强ぢ
伪装坚强ぢ 2021-01-28 16:03

Once a user has selected a file with the open file dialog, how can I handle this action? For example, if the user has selected a .txt file and has opened it, how can it get the

3条回答
  •  耶瑟儿~
    2021-01-28 16:48

    Dim dlg_open As New OpenFileDialog()
    If (dlg_open.Show() <> DialogResult.OK) Then Return
    
    'if a textfile, then
    Dim content As String() = IO.File.ReadAllLines(dlg_open.FileName)
    
    'if an image, then
    Dim img As New Bitmap(dlg_open.FileName)
    

    You should put Try...Catch blocks around all operations dealing with IO, you will not be able to prevent all exceptions.

提交回复
热议问题