pramod
pramod

Reputation: 373

how to set image file path in app config file?

I have a console application and it has a folder images in it.

How can I set path in the app.config file similar to below:

~/images/logo.jpg

../images/logo.jpg

Upvotes: 2

Views: 8027

Answers (2)

Heshan Perera
Heshan Perera

Reputation: 4630

Are you asking how to add those file names to the app.config?

if so...

<appSettings>
    <add key="image1" value="~/images/logo.jpg"/>
</appSettings>

This can be read by adding a reference to System.Configurations

And then calling ConfigurationManager.AppSettings["image1"];

You can access any value in the app.config using the Configuration manager.

Upvotes: 2

Pranay Rana
Pranay Rana

Reputation: 176906

Use System.IO.Path.Combine method to combine a base path with a relative path like:

 System.IO.Path.Combine(Environment.CurrentDirectory, relativePath);

Environment.CurrentDirectory in the above line with whatever base path you want.

Upvotes: 2

Related Questions