0

Case: I have a Desktop application in which I need to show Customized Images as per Logged In Vendor. So, in App.config, the image file is added as a key:

<add key="Logo" value="companylogo_2.jpg"/>

How to consume it in ToolstripLabel control?

Note: In App.config file, value does not contain full path of image, just the Name of Image

Trials:
1.

smallImageList.Images.Add(Image.FromFile(ConfigurationSettings.AppSettings["Logo"]));

2.

string CurrDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
smallImageList.Images.Add(Image.FromFile(Path.Combine(CurrDirectory,ConfigurationSettings.AppSettings["Logo"])));
Vikrant
  • 4,920
  • 17
  • 48
  • 72

1 Answers1

1

Thanks for zero Help! Anyways, I figured it out.

Steps :
Read the value from App.config:

public string imgLogo = System.Configuration.ConfigurationSettings.AppSettings["Logo"].ToString();

Get full path using : Assembly.GetExecutingAssembly().Location as:

`System.Drawing.Image myImage = Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\" + imgLogo + "");`

Assign value to toolStripLabel as:

toolStripLabel1.Image = myImage;
Vikrant
  • 4,920
  • 17
  • 48
  • 72