Open a file in Visual Basic.Net

Download
Download is available until [expire_date]
  • Version
  • Download 55
  • File Size 106.99 KB
  • File Count 1
  • Create Date March 8, 2016
  • Last Updated March 8, 2016

Open a file in Visual Basic.Net

Open a file in Visual Basic.Net

Example source code in visual basic.net that allows you to open a file through our vb.net program.

The program will also get the information of the file such as filename, path and file size. You can also filter the file type you want to view and open (pdf, docx and exe).

Source code:

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If RadioButton1.Checked = True Then
            OpenFileDialog1.Filter = "All Files (*.*)|*.*"
        ElseIf RadioButton2.Checked = True Then
            OpenFileDialog1.Filter = "Exe Files (*.exe)|*.exe"
        ElseIf RadioButton3.Checked = True Then
            OpenFileDialog1.Filter = "Doc Files (*.doc)|*.docx"
        ElseIf RadioButton4.Checked = True Then
            OpenFileDialog1.Filter = "PDF Files (*.pdf)|*.pdf"
        End If

        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim getfilesize As System.IO.FileInfo
            TextBox1.Text = OpenFileDialog1.FileName
            TextBox2.Text = OpenFileDialog1.SafeFileName
            'OpenFileDialog1.


            getfilesize = My.Computer.FileSystem.GetFileInfo(TextBox1.Text)
            TextBox3.Text = "File is " & getfilesize.Length & " bytes."

            System.Diagnostics.Process.Start(TextBox1.Text)

        End If
    End Sub
End Class
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.