.net c# cannot find img resources when open with exe

Posted by okuryazar on Stack Overflow See other posts from Stack Overflow or by okuryazar
Published on 2010-03-22T08:09:52Z Indexed on 2010/03/22 8:11 UTC
Read the original article Hit count: 367

Filed under:
|
|
|

Hello,

My exe processes text documents and I want to be able to right click on documents, select open with and point to my exe file. I can double click on my exe and choose a file to process with OpenFileDialog and it works fine. However, when I do open with, I get FileNotFound error.

Here is the error log:

System.IO.FileNotFoundException: attention.jpg
   at System.Drawing.Image.FromFile(String filename, Boolean useEmbeddedColorManagement)
   at System.Drawing.Image.FromFile(String filename)
   at ImzaDogrulamaUygulamasi.frmCertificate.FillTreeView() in D:\VSS\SOURCE\VS2008\EGA\ImzaDogrulamaUygulamasi\ImzaDogrulamaUygulamasi\frmCertificate.cs:line 76
   at ImzaDogrulamaUygulamasi.frmCertificate.Form2_Load(Object sender, EventArgs e) in D:\VSS\SOURCE\VS2008\EGA\ImzaDogrulamaUygulamasi\ImzaDogrulamaUygulamasi\frmCertificate.cs:line 244
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

and this is how I add my images in my code, all resources are in the same directory with the exe file:

    ImageList myImageList = new ImageList();

    myImageList.Images.Add(Image.FromFile("attention.jpg"));
    myImageList.Images.Add(Image.FromFile("sandglass.jpg"));
    myImageList.Images.Add(Image.FromFile("11.JPG"));
    myImageList.Images.Add(Image.FromFile("checkGif.jpg"));

    treeView1.ImageList = myImageList;

Any help is much appreciated. Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET