newbie ques openfiledialog

M

mp

hello all, just starting to try to learn c#, sorry for the dumb question
using c# express on winxp pro
started a new project wpf type
added a button to call openfiledialog
i get type or namespace name not found are you missing... error
i get this on openfiledialog, so went to help to find it's heirarchy and it
says it in PresentationFramework.Windows soemthing(found it in help last
night, now i can't find it again to get the exact name)

but even PresentationFramework gives the same error

there is mention of an openfiledialog component but that seems to be in
windows.forms which appears to be a different world than wpf as that control
isn't found in the toolbox
System..::.Object
System..::.MarshalByRefObject
System.ComponentModel..::.Component
System.Windows.Forms..::.CommonDialog
System.Windows.Forms..::.FileDialog
System.Windows.Forms..::.OpenFileDialog

heres' my snippet that has the compile errors
namespace WpfApplication1

{

public partial class Window1 : Window

{

public Window1()

{

InitializeComponent();

}

private void button1_Click(object sender, RoutedEventArgs e)


{

Stream myStream = null;

//OpenFileDialog not found error:

OpenFileDialog openFileDialog1 = new OpenFileDialog();

//PresentationFramework name not found

PresentationFramework.Win(something).OpenFileDialog openFileDialog1 = new
OpenFileDialog();

how do i get access to the open and save dialogs in c# wpf?
Thanks
mark
 
P

Peter Duniho

hello all, just starting to try to learn c#, sorry for the dumb question
using c# express on winxp pro
started a new project wpf type
added a button to call openfiledialog
i get type or namespace name not found are you missing... error
i get this on openfiledialog, so went to help to find it's heirarchy and
it
says it in PresentationFramework.Windows soemthing(found it in help last
night, now i can't find it again to get the exact name)

Then you really should find it again before you post your question. It
can be very difficult to answer a question when the person asking hasn't
even provided all of the information that they are presumably working with.
but even PresentationFramework gives the same error

there is mention of an openfiledialog component but that seems to be in
windows.forms which appears to be a different world than wpf as that
control
isn't found in the toolbox
System..::.Object
System..::.MarshalByRefObject
System.ComponentModel..::.Component
System.Windows.Forms..::.CommonDialog
System.Windows.Forms..::.FileDialog
System.Windows.Forms..::.OpenFileDialog

As far as I know, for the desktop, there's only two namesspaces in which
you can find the OpenFileDialog class: in System.Windows.Forms, and in
Microsoft.Win32.

To successfully use a class, your project must reference the assembly in
which that class is found. For OpenFileDialog, that would be either
System.Windows.Forms.dll or PresentationFramework.dll. When using the
class, you must either provide a fully-qualified name (i.e. including the
complete namespace), or you also need an appropriate "using" statement at
the beginning of your code file.

From your relatively vague question, it appears that you should be
specifying "Microsoft.Win32.OpenFileDialog" as the class name, and adding
PresentationFramework.dll to your project references. Please try doing
that and see if that fixes your problem.

Thanks,
Pete
 
M

mp

Peter Duniho said:
As far as I know, for the desktop, there's only two namesspaces in which
you can find the OpenFileDialog class: in System.Windows.Forms, and in
Microsoft.Win32.
thanks that was it Microsoft.Win32

now the error is different
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) <---- error here at
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?)

so i'm off to figure that one out!?!

Thanks
mark
 
P

Peter Duniho

[...]
if(openFileDialog1.ShowDialog() == DialogResult.OK) <---- error here at
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?)

so i'm off to figure that one out!?!

When in doubt, read the documentation. It's the first place you should
always look.

http://msdn.microsoft.com/en-us/library/ms614336.aspx
 
M

mp

When in doubt, read the documentation. It's the first place you should
always look.

http://msdn.microsoft.com/en-us/library/ms614336.aspx

Thanks for the link
(that's what i do, check the help first)
however, due to my ignorance i don't always find what i need so after
extended period of trying different search terms i come to the ngs
in this case i'm starting to realize the example i was trying to convert to
wpf must have come from windows.forms, as there's apparently no dialogresult
object in wpf that's why it's not working i guess
Thanks
mark
 
P

Peter Duniho

[...]
in this case i'm starting to realize the example i was trying to convert
to
wpf must have come from windows.forms, as there's apparently no
dialogresult
object in wpf that's why it's not working i guess

Even if there were a DialogResult type in WPF, it wouldn't help. The
method you're calling doesn't return a value of the type DialogResult.

Looking at the documentation, you can see what the type of the return
value is, as well as what the meaning of the possible values for that type.

Pete
 
M

mp

Peter Duniho said:
[...]
in this case i'm starting to realize the example i was trying to convert
to
wpf must have come from windows.forms, as there's apparently no
dialogresult
object in wpf that's why it's not working i guess

Even if there were a DialogResult type in WPF, it wouldn't help. The
method you're calling doesn't return a value of the type DialogResult.

Looking at the documentation, you can see what the type of the return
value is, as well as what the meaning of the possible values for that
type.

Pete

right, I see that
thanks for setting me straight
mark
 
J

Jason Becker

MP,

Since the previous responses to your inquiry did not help me in the slightest, I thought I might help others who happen across this problem for me to post the solution I found.

The following code worked for me:

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$dlg = new-object("System.Windows.Forms.OpenFileDialog")
$dialogresult = $dlg.showdialog()
if($dialogresult -eq [Windows.Forms.DialogResult]::OK)
{
Write-Host "WORKED!"
}


Happy Easter!



mp wrote:

Re: newbie ques openfiledialog
22-Sep-09

right, I see tha
thanks for setting me straigh
mark

Previous Posts In This Thread:

newbie ques openfiledialog
hello all, just starting to try to learn c#, sorry for the dumb questio
using c# express on winxp pr
started a new project wpf typ
added a button to call openfiledialo
i get type or namespace name not found are you missing... erro
i get this on openfiledialog, so went to help to find it is heirarchy and i
says it in PresentationFramework.Windows soemthing(found it in help las
night, now i cannot find it again to get the exact name

but even PresentationFramework gives the same erro

there is mention of an openfiledialog component but that seems to be i
windows.forms which appears to be a different world than wpf as that contro
is not found in the toolbo
System..::.Objec
System..::.MarshalByRefObjec
System.ComponentModel..::.Componen
System.Windows.Forms..::.CommonDialo
System.Windows.Forms..::.FileDialo
System.Windows.Forms..::.OpenFileDialo

heres' my snippet that has the compile error
namespace WpfApplication



public partial class Window1 : Windo



public Window1(



InitializeComponent()



private void button1_Click(object sender, RoutedEventArgs e



Stream myStream = null

//OpenFileDialog not found error

OpenFileDialog openFileDialog1 = new OpenFileDialog()

//PresentationFramework name not foun

PresentationFramework.Win(something).OpenFileDialog openFileDialog1 = ne
OpenFileDialog()

how do i get access to the open and save dialogs in c# wpf
Thank
mark

Re: newbie ques openfiledialog
Then you really should find it again before you post your question. I
can be very difficult to answer a question when the person asking has no
even provided all of the information that they are presumably working with

As far as I know, for the desktop, there is only two namesspaces in whic
you can find the OpenFileDialog class: in System.Windows.Forms, and i
Microsoft.Win32

To successfully use a class, your project must reference the assembly i
which that class is found. For OpenFileDialog, that would be eithe
System.Windows.Forms.dll or PresentationFramework.dll. When using th
class, you must either provide a fully-qualified name (i.e. including th
complete namespace), or you also need an appropriate "using" statement a
the beginning of your code file

From your relatively vague question, it appears that you should b
specifying "Microsoft.Win32.OpenFileDialog" as the class name, and addin
PresentationFramework.dll to your project references. Please try doin
that and see if that fixes your problem

Thanks
Pete

Re: newbie ques openfiledialog
thanks that was it Microsoft.Win3

now the error is differen
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) <---- error here a
dialogresult.o

Error 1 'System.Nullable<bool>' does not contain a definition for 'OK' an
no extension method 'OK' accepting a first argument of typ
'System.Nullable<bool>' could be found (are you missing a using directive o
an assembly reference?

so i'm off to figure that one out!?

Thank
mark

Re: newbie ques openfiledialog
When in doubt, read the documentation. it is the first place you should
always look.

http://msdn.microsoft.com/en-us/library/ms614336.aspx

Re: newbie ques openfiledialog
Thanks for the link
(that is what i do, check the help first)
however, due to my ignorance i do not always find what i need so after
extended period of trying different search terms i come to the ngs
in this case i'm starting to realize the example i was trying to convert to
wpf must have come from windows.forms, as there is apparently no dialogresult
object in wpf that is why it is not working i guess
Thanks
mark

Re: newbie ques openfiledialog
Even if there were a DialogResult type in WPF, it would not help. The
method you are calling does not return a value of the type DialogResult.

Looking at the documentation, you can see what the type of the return
value is, as well as what the meaning of the possible values for that type.

Pete

Re: newbie ques openfiledialog
right, I see that
thanks for setting me straight
mark


Submitted via EggHeadCafe - Software Developer Portal of Choice
File-Based Cache for Web and non-Web Apps plus Extend ASP.NET 4.0 OutputCacheProvider
http://www.eggheadcafe.com/tutorial...dfe-9f7a28f4d58e/filebased-cache-for-web.aspx
 
F

Family Tree Mike

MP,

Since the previous responses to your inquiry did not help me in the slightest, I thought I might help others who happen across this problem for me to post the solution I found.

The following code worked for me:

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$dlg = new-object("System.Windows.Forms.OpenFileDialog")
$dialogresult = $dlg.showdialog()
if($dialogresult -eq [Windows.Forms.DialogResult]::OK)
{
Write-Host "WORKED!"
}


Happy Easter!

What language is that???
 
K

Konrad Neitzel

Hi Mike!

Family Tree Mike said:
MP,

Since the previous responses to your inquiry did not help me in the
slightest, I thought I might help others who happen across this problem
for me to post the solution I found.

The following code worked for me:

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$dlg = new-object("System.Windows.Forms.OpenFileDialog")
$dialogresult = $dlg.showdialog()
if($dialogresult -eq [Windows.Forms.DialogResult]::OK)
{
Write-Host "WORKED!"
}


Happy Easter!

What language is that???

Without further investigation, I would say that he wrote a powershell
script.

With kind regards,

Konrad
 

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