How do I open a file from a specific directory in . PDF in Visual Basic 6?

Asked

Viewed 5,685 times

1

I created an application which saves files in a specific directory. What I would like is to click a button, I can open this file . pdf.

  • If it’s VB why the C tag#?

  • Why I program in both languages. If there is a solution in C# maybe I can transcribe to vb6

  • So I suggest you remove the reference to VB from the question title and put this information in the body.

3 answers

2

C# and Windowsforms

private void button1_Click(object sender, System.EventArgs e)
{
    OpenFileDialog openFileDialog1 = new OpenFileDialog();

    openFileDialog1.InitialDirectory = "c:\\" ;
    openFileDialog1.Filter = "PDF files (*.pdf)|*.pdf" ;

    if(openFileDialog1.ShowDialog() == DialogResult.OK)
    {
        System.Diagnostics.Process.Start(openFileDialog1.FileName);
    }
}

The above code opens, when the button is clicked, a dialog where a pdf file can be selected.
The file will be opened by the application associated with the extension .pdf.

0

'Declarepara Executar
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long


'Sub para Executar
Sub subExecuta(strPath As String)
    ShellExecute 0, "Open", strPath, "", "", vbNormalFocus
End Sub


'Executa
call subExecuta(App.Path & "\file.pdf")

0

When dragging an Openfiledialog type control, just go to the 'designer' file and set the properties, as the previous answer.

If you need to put more than one option in the 'Filter' property':

openFileDialog1.Filter =  "Texto|*.txt;*.dat;*.csv|"   + _
                          "imagem|*.jpg;*.jpeg;*.gif|" + _
                          "audio|*.mp3;*.aac;*.wma|"   + _
                          "planilha Excel|*.xls|"      + _
                          "Todos os arquivos|*.*"

Note: 'Filter' property only takes one string. I only broke the line for easy reading.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.