Loading image from code using relative path in Windows Forms

For my program, Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location) returns
C:\code\test\Junk\bin\Debug.

cell.Value = Image.FromFile(
  Path.Combine (
     Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location),
     "Resources/warning_Icon"));

Of course, usually you would embed the resources in your assembly unless you want to change them without a recompile.

Leave a Comment