Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
file browse button code:

C#
private void RibbonButton_Click_1(object sender, RoutedEventArgs e)
       {
           Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
           dlg.InitialDirectory = @"c:\";
           dlg.Filter = "Image files (*.tif)|*.tif|All Files (*.*)|*.*";
           dlg.RestoreDirectory = true;
           bool? result = dlg.ShowDialog();
           if (dlg.ShowDialog == System.Windows.Forms.DialogResult.OK)
           {
               string selectedFileName = dlg.FileName;
               Label1.Content = selectedFileName;
               BitmapImage bitmap = new BitmapImage();
               bitmap.BeginInit();
               bitmap.UriSource = new Uri(selectedFileName);
               bitmap.EndInit();
               Imageviewer1.Source = bitmap;
           }
Posted
Updated 25-Nov-15 21:54pm
v3
Comments
phil.o 25-Nov-15 7:18am    
Did you try to debug? And why are you executing the ShowDialog method twice?
Moreover, Win32.OpenFileDialog.ShowDialog() will never return a System.Windows.Forms.DialogResult; it will return a Nullable<bool> instead.
ZurdoDev 26-Nov-15 8:55am    
Looks like you should post as solution. You got OP on the right track.
phil.o 26-Nov-15 11:48am    
Done, thanks :)
ZurdoDev 26-Nov-15 11:55am    
Indeed. You did it two well. ;)
phil.o 26-Nov-15 12:36pm    
Oups ^^

1 solution

C#
if (result.HasValue && result.Value)

should do it, instead of
C#
if (dlg.ShowDialog == System.Windows.Forms.DialogResult.OK)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900