0

I created a game in c #, the user must select the image interloper from those displayed on the buttons, the problem I am having is to export the exercise of other PCs, I'm forced to copy all the folders and all images ? I currently do it this way:

string [] files = Directory.GetFiles (".. \ \ .. \ \ img4");
image_target_path = ".. \ \ .. \ \ img4 \ \ hammer.png";
Random rnd = new Random ();
files.OrderBy files = (x => rnd.Next ()). ToArray ();

hammer is the image interloper, this works but when I run it on another PC I have to copy the folders, there is a solution?

1 Answer 1

1

You could always embed the images as resources into your executable.

There are a number of different options detailed in this post: Load image from resources area of project in C#.

If you are referencing files by their path on disk, you will always need to copy the folders and files to wherever your code is being deployed.

2
  • Thank you for the response, all the images are resources, but i would to know if there is a method to eliminate the path ..\\.\\.., because ig i change the location of my .exe the project doesn't works Jul 8, 2013 at 13:40
  • Directory.GetFiles will never load a compiled resource. Compiled resources are contained within the executable or DLL. You are loading these files from disk, not from the resources embedded in your application. In order to eliminate using the `..\\..\` in your path, you must either install the application to one directory that will never change, or use embedded resources. Steven A Lowe's answer at stackoverflow.com/questions/278838/… tells you how to do this.
    – Sean Airey
    Jul 8, 2013 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.