Aniruddha Acharya

Aniruddha Acharya

  • NA
  • 304
  • 20.2k

Enable button on only text file select

Nov 20 2017 11:44 PM
Hi,
I want to how to enabled button when only select .txt file from  browse openFileDialog window  .
 
I am using this code on browse button click .
 
private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
openFileDialog.DefaultExt = ".txt";
openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
result = openFileDialog.Filter;
if (openFileDialog.ShowDialog() == true) //Open file dialog window
{
txtpath = openFileDialog.FileName;
FileNameTextBox.Text = txtpath;
btnCompaire.IsEnabled = true; openFileDialog.
}
 
 
Only for select .txt file . if other any file [.ppt,pdf,...etc]  then disabled this button
 
 
Thanks

Answers (4)