wpf version of OpenFileDialog

M

mp

Trying to figure out how to get an openFile/saveFile dialog in a wpf context
according to the help files it's the same object as windows.forms version
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/wpf_conceptual/html/8a157e6b-8054-46db-a5cf-a78966acc7a1.htm
quote "The OpenFileDialog class is a WPF wrapper around the Win32 control. "

so i try this sample also from the help files

using System.IO;

//using System.Windows.Forms;

using Microsoft.Win32;


namespace WpfOpenFileDialog

{

/// <summary>

/// Interaction logic for Window1.xaml

/// </summary>

public partial class Window1 : Window

{

public Window1()

{

InitializeComponent();

}

private void button1_Click(object sender, System.EventArgs e)

{

Stream myStream = null;

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.InitialDirectory = "c:\\";

openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";

openFileDialog1.FilterIndex = 2;

openFileDialog1.RestoreDirectory = true;

if (openFileDialog1.ShowDialog ( ) == DialogResult.OK)

{

try

{

if ((myStream = openFileDialog1.OpenFile()) != null)

{

using (myStream)

{

// Insert code to read the stream here.

}

}

}

catch (Exception ex)

{

MessageBox.Show("Error: Could not read file from disk. Original error: " +
ex.Message);

}

}

}


}

}



the line throwng error:

if (openFileDialog1.ShowDialog ( ) == DialogResult.OK)

Error 1 'System.Nullable<bool>' does not contain a definition 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?)

what assembly should I be referencing?

thanks

mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top