tags:

views:

42

answers:

4

I have an image in my project that I want to go along with the program. If I was going to use something like BitmapImage() what would I use for the path? I don't want to use the c:\blah blah blah because that could change depending on were it is on each PC. Is it called a "relative path"?

A: 

You want to use Environment.CurrentDirectory, or System.Reflection.Assembly.GetExecutingAssembly().Location (which is the location of the executable--you can use System.IO.FileInfo to get to the directory).

Russ
+1  A: 

You probably want to think about making your image an embedded resource. This will embed it in the exe. This article should explain it.

Tim
+1  A: 

You can and also should put your images into the projects resoucre-file (embed it).

Then, you can access your resource at runtime like any other object.

System.Drawing.Bitmap bitmap1 = myProject.Properties.Resources.Image01;

Look at this MSDN page for more information: http://msdn.microsoft.com/en-us/library/7k989cfy%28VS.80%29.aspx

Emiswelt
I made a bitmap by clicking on my project folder and selecting add bmp and tried to use uploadImage.Source = myProjectProperties.Resources.Bitmap1.bmp; and it said myProject.Properties.Resources does not contain a definition for Bitmap1.bmp
rd42
THanks, I used this to help: http://www.csharp411.com/embedded-image-resources/
rd42
Glad it worked out for you :)
Emiswelt
A: 

If you want to save the file to the users profile so it will be in the same location no matter where the application is you can get the path with the following

string s = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);