I am building an application that needs to browse for an excel file and load it.
The issue I'm facing so far is this:
When debugging the application automatically opens the browse for file dialog without having me to click the browse button.
namespace MassyDataMigration
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnLoad_Click(object sender, EventArgs e)
{
LoadNewFile();
}
private void LoadNewFile()
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Open required excel file";
ofd.Filter = "EXCEL 97-03 Files|*.xls|EXCEL Files|*.xlsx";
ofd.InitialDirectory = @"C:\";
System.Windows.Forms.DialogResult dr = ofd.ShowDialog();
if (dr == DialogResult.OK)
{
UserSelectedFilePath = ofd.FileName;
}
}
public string UserSelectedFilePath
{
get
{
return tbFilePath.Text;
}
set
{
tbFilePath.Text = value;
}
}
private void tbFilePath_TextChanged(object sender, EventArgs e)
{
}
}
}
What am I doing wrong?
Sorry for top one this time now i debug to confirmly check the solution: it is working fine and showing browse dialog on debugging put his code:
OpenFileDialog ofd = new OpenFileDialog();
DialogResult dr = ofd.ShowDialog();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With