I am trying to use OpenFileDialog as in the code below, but the compiler shows the exception System::NullReferenceException, once I put the the code between try and catch block, no exception is thrown, but now dialog is shown!?
try
{
if(openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
this->textBox18->Text=openFileDialog1->FileName->ToString();
}
}
catch(System::NullReferenceException^ e){ e->Message;}
You must create an instance of the
OpenFileDialogclass before using it. In this code segment:You are just declaring a variable of the type
OpenFileDialog(initialized withnull) but you need to instantiate it before being able to use it with