1

Application cannot find my ico file. Where should I add picture ?
I get an unhandled exception of type 'System.IO.FileNotFoundException'

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.notifyIcon1.Icon = new Icon("mmm.ico");
            this.ShowInTaskbar = true;
        }
    }
}

enter image description here

Raskolnikov
  • 3,791
  • 9
  • 43
  • 88

1 Answers1

5

That is because you try to load the icon from you application folder, but it is in your Project folder (move the Icon-File to the Bin/Debug or Bin/Release folder).

If you want to load your icon out of your assembly, set it as an embedded ressource and load it over: Assembly.GetExecutingAssembly().GetManifestResourceStream('<<Path to your ressource>>')

Can't load a manifest resource with GetManifestResourceStream() Best way to get the code-base: Gets the location of the assembly

Community
  • 1
  • 1
BendEg
  • 20,098
  • 17
  • 57
  • 131
  • When using first part of the answer don't forget to use *absolute path* to the resource - check out http://stackoverflow.com/questions/3163495/better-way-to-get-the-base-directory how to get base path. – Alexei Levenkov Jan 23 '15 at 15:44
  • Thank you, added it to my answer – BendEg Jan 23 '15 at 15:47
  • 1
    _"move the Icon-File to the Bin/Debug or Bin/Release folder"_ - no, don't do that. Those folders are by convention. You shouldn't add those folders to version control. Just set the "Copy to Output Directory" property properly. – CodeCaster Jan 23 '15 at 15:55