Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, April 18, 2019 2:48 PM
How do I open a PDF file without the Open file dialog box showing up? I have a Winform and using AcroPDFLib and AxAcroPDFLib as reference. The PDF file is is the Bin folder I cant figure out how to disable the box and use relative path.
private void button1_Click(object sender, EventArgs e)
{
{
OpenFileDialog dlg = new OpenFileDialog();
// set file filter of dialog
dlg.Filter = "pdf files (*.pdf) |*.pdf;";
dlg.ShowDialog();
if (dlg.FileName != null)
{
// use the LoadFile(ByVal fileName As String) function for open the pdf in control
axAcroPDF1.LoadFile(dlg.FileName);
}
}
}
}
}
Booney440
All replies (8)
Thursday, April 18, 2019 8:57 PM âś…Answered
Sorry, that is a typo. Make the `filename` local variable and the variable passed to `LoadFile` use the same case. C# is case sensitive.
Michael Taylor http://www.michaeltaylorp3.net
Thursday, April 18, 2019 5:27 PM
Pass the name of the file you want to open as a parameter to LoadFile instead of using dlg.FileName.
var filename = "MyPdf.pdf";
axAcroPDF1.LoadFile(filename);
Michael Taylor http://www.michaeltaylorp3.net
Thursday, April 18, 2019 6:07 PM
if i add a form load how do i tie the button click into it or just have it load automatically?
Booney440
Thursday, April 18, 2019 6:19 PM
Not really sure what you're asking here. Is this a new question? What does form load and a button click have to do with the opening of a PDF? Are you trying to run the code you posted initially in a form load call? If so then move the logic into a private method and have your button click and/or form load handler call the method.
Michael Taylor http://www.michaeltaylorp3.net
Thursday, April 18, 2019 6:36 PM
Same question I dont understand how to add your suggestion to keep the dialog box from opening I just want the file to load on button click.
Booney440
Thursday, April 18, 2019 6:42 PM
private void button1_Click(object sender, EventArgs e)
{
var filename = "MyPdf.pdf";
axAcroPDF1.LoadFile(fileName);
}
Loads MyPdf.pdf when the button is clicked. Is that what you want?
Michael Taylor http://www.michaeltaylorp3.net
Thursday, April 18, 2019 8:53 PM
filename assigned but its value never used.
Booney440
Thursday, April 18, 2019 9:31 PM
Thanks that did the trick.
Booney440