I have two radio buttons and a regular button - button2.
I've created an if else statement that checks which of the radio buttons is clicked and accordingly preforms a given task. In particular, if:
- Radio button 1 is clicked: Ask's to select one pdf file, opens a axAcroPDF1 connection and outputs the OpenFileDialog FileName into a textbox
- Radio button 2 is clicked: Something else
- No radio button is clicked: Sends a messege.. select a file.
This is my attempt:
{
if (radioButton1.Checked == true)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "PDF|*pdf";
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
axAcroPDF1.Show();
axAcroPDF1.src = ofd.FileName;
}
textBox1.Text = ofd.FileName;
MessageBox.Show(ofd.FileName);
}
else if (radioButton2.Checked == true)
{
OpenFileDialog ofd3 = new OpenFileDialog();
ofd3.Filter = "PDF|*pdf";
textBox1.Text = ofd3.InitialDirectory + ofd3.FileName;
if (ofd3.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
axAcroPDF1.Show();
}
}
else if (radioButton2.Checked == false & radioButton1.Checked == false)
{
MessageBox.Show("Please select a processing option");
}
else
{
MessageBox.Show("Error.");
}
}
The issue is that I can't extract the FileName string in: textBox1.Text = ofd.FileName;
Basically, this returns an empty string. I'm not sure how this is possible, when in fact the axAcroPDF1.src successfully opens the selected pdf.
Any ideas?
textBox1.Text = ofd3.FileName;
intoif
- Note:OpenFileDialog.FileName
will have a value afterOpenFileDialog.ShowDialog()
andInitialDirectory
isstring.Empty
as default -HTH ;). – shA.telse
will never be hit and can be removed. Your lastelse if
is redundant (failing the first two tests implies the third)...you can replace that with anelse
. – pinkfloydx33