how to solve this error in openfileDialog

Posted by Gow.Net under WPF on 8/7/2012 | Points: 10 | Views : 2194 | Status : [Member] | Replies : 2
My code:

OpenFileDialog obj_openfile = new OpenFileDialog();
obj_openfile.Filter = "Select file|*.txt|*.docs|*.doc";
obj_openfile.Title = "Selct Your File";
obj_openfile.FileName = "";
if (obj_openfile.ShowDialog() == true)
{
FileName = obj_openfile.FileName;
}

My Error::Operator '==' cannot be applied to operands of type 'System.Windows.Forms.DialogResult' and 'bool'

gowthaman8870226416


Responses

Posted by: CGN007 on: 8/7/2012 [Member] Silver | Points: 25

Up
0
Down
Hope this works
Nullable<bool> result =obj_openfile.ShowDialog();

if (result == true)
{
FileName = obj_openfile.FileName;
}


Please try and let me know the result...


Happy learning!

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: CGN007 on: 8/7/2012 [Member] Silver | Points: 25

Up
0
Down
Another method...
 DialogResult result =obj_openfile.ShowDialog();

if (result == System.Windows.Forms.DialogResult.OK)
{
FileName = obj_openfile.FileName;
}


Please try and let me know the result...

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response