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

1

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

    
asked by anonymous 30.04.2015 / 20:02

3 answers

1

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 code above 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 .pdf extension.

    
30.04.2015 / 20:26
0

When dragging a control of type OpenFileDialog, simply go to the file 'designer' and set the properties, according to 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: The 'Filter' property receives only one string. I just broke the line for easy reading.

    
29.06.2015 / 21:56
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")
    
14.10.2015 / 15:41