c# - Null Reference Exception openFileDialog -


code:

namespace bla_bla_bla  {   public delegate void pathselected(string path);  //...   public partial class form1 : form   {       public pathselected onpath;  //...   private void button1_click(object sender, eventargs e)   {      openfiledialog openfiledialog1 = new openfiledialog();     openfiledialog1.filter ="images (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif";     openfiledialog1.multiselect = true;     openfiledialog1.showdialog();     if (openfiledialog1.showdialog() == dialogresult.ok)     if (openfiledialog1.safefilename != null)     onpath(openfiledialog1.safefilename);   } 

question:

why getting null reference exeption in last row?

error:

(original poster should add such here)

don't understand question, or why go need delegate, try on button1 click event handler:

int size = -1; dialogresult result = openfiledialog1.showdialog();  if (result == dialogresult.ok) {     string file = openfiledialog1.filename;     try {         string text = file.readalltext(file);         size = text.length;     }     catch (ioexception) {     } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -