I have folder "Icons".
I need to access same in order to add an icon to imageList
.
I'm using app.config file in that have a relative path.
<add key="doc" value="..\Icons\_Microsoft Office Excel 97-2003 Worksheet.ico" />
and I'm using below code to add it to imgList
,however it throws System.IO.FileNotFoundException
:
smallImageList.Images.Add(Image.FromFile(ConfigurationSettings.AppSettings["doc"]));
What's the problem here?
Try adding the current running path:
smallImageList.Images.Add(Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationSettings.AppSettings["doc"])));
You might need to concatenate that with System.AppDomain.CurrentDomain.BaseDirectory.
I'd guess that FromFile is relative to the current working directory which is prone to change. The other thing to consider would be embedding the images in the assembly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With