Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning everyone, so I am making a Project in Windows Forms and I have one question. In my Project I am using images, that are in same Faile as my Project, I have to compare screenshot with images so I have imported those images in Project File but how can get Images from there for exmaple: my Project path is : "C:\\Users\\Dave\\Documents\\Visual Studio 2012\\Projects\\pro1" and Path for my images is : "C:\\Users\\Dave\\Documents\\Visual Studio 2012\\Projects\\pro1\\images" . How can I call images from Project File without writing Full Path ? for exp. without this - "C:\\Users\\Dave\\Documents\\Visual Studio 2012\\Projects\\pro1\\images\\bit.png" .

What I have tried:

I think that writing full Path isn't a good idea because that it will always search images from directory "C:\\Users\\Dave\\Documents\\Visual Studio 2012\\Projects\\pro1\\images" and this directory will be only on my Computer and on another PC it willn't work. Can someone Help me with this ?
Posted
Updated 9-Jul-16 2:22am

You should always use one of the automatically created Windows locations to store program and other data. See Store and retrieve settings and other app data[^] and ApplicationData class - Windows app development[^].
 
Share this answer
 
I think you have three options:

  1. Store the images as resource inside your application and load them from there.
  2. Copy the image files upon installation to the same directory as your application and load it from there.
  3. Store the image files in the application data path.


For the first option see Load image from resources area of project in C# - Stack Overflow[^].

For the second option see Get application path in c#[^] to get the directory where your application has been stored and append the image file name.

The third option is described in Richard's solution.

The application data path should be used to store data generated during run-time. So you should use this when the images has to be changed during run-time. If the images will not be updated during run-time, option 1 and 2 may be used instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900