Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi ,

I am trying to upload a image from the local drive to the visual studio 2010(WPF).

I got an error message stating System.Nullable<bool> does not contain a defition for 'OK' and no extension method 'OK' accepting a first argument of type System.Nullable<bool>could be found (are you missing a using directive or an assembly reference?)

Please find the code :
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;


 namespace Image_Upload
 {
       /// <summary>
      /// Interaction logic for MainWindow.xaml
     /// </summary>
     public partial class MainWindow : Window
      {
         public MainWindow()
         {
             InitializeComponent();
             ImageViewer1.Source = new BitmapImage(new Uri("creek.jpg",       UriKind.Relative));
        }

        private void Browse_ButtonClick(object sender, RoutedEventArgs e)
          {
           
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.InitialDirectory = "c:\\";
            dlg.Filter = "Image files (*.jpg)|*.jpg|All Files (*.*)|*.*";
            dlg.RestoreDirectory = true;
          
            
            if(dlg.ShowDialog() == DialogResult.OK)     
            {   
                string selectedFileName = dlg.FileName;
                FileNameLabel.Content = selectedFileName;
                BitmapImage bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.UriSource = new Uri(selectedFileName);
                bitmap.EndInit();
                ImageViewer1.Source = bitmap;
            }
        }

Please suggest me .

Thanks in advance.
Posted
Updated 20-Oct-12 3:28am
v2

1 solution

The dialog doesn't return a DialogResult,
but a bool?.

The bool? is a Nullable type[^],
follow the link for more information.
 
Share this answer
 

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