jonasPamm
jonasPamm

Reputation: 97

C# System.IO How to get path to a folder in my project

[picture]

In my program I want to use this image (the image marked in the picture) but how can I get the path of this picture without using an absolute path (it should work on any pc without changing a path in the code)?

Can someone post a example code of opening a filestream with this picture called "Jonas.jpg"?

Upvotes: 1

Views: 273

Answers (1)

PippoZucca
PippoZucca

Reputation: 161

You can get the path of your application using Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

and then use a Path.Combine, adding the local path.

Image.FromFile(
  Path.Combine (
     Path.GetDirectoryName (Assembly.GetExecutingAssembly().Location),
     "Persons/Jonas.jpg"));

Upvotes: 3

Related Questions