Answer» I been storing my image and other files in "bin" folder ever since, because is easy to write file path. The problem with that is when publishing the application, you will lose those path making the program not recognising my files and throwing errors. How can i solve this problem without using my resource folder because you can not access files using string. Where should i create my new folder and what directory path should i use so when publish, it will not cause an errors?
Thank you Personally When I start a new program I have it load resources (images, sounds) from the Application directory- using AppDomain.CurrentDomain.BaseDirectory. (this is the directory the executable is RUNNING from). Most of the loading of images/sounds is done by a set of classes I made explicitly for this purpose- SoundManager and ImageManager. The former uses a Library I found online, the latter loads Images and caches them. I GENERALLY make them static properties of a ubiquitous class, so that there is only one instance. I then either use a variable initializer to create them (their constructors accept a file path) or a static constructor. the latter is what I eventually settle on, since it allows the image and sound folders to be moved via an INI file that also get's loaded.
As a general rule Program resources should be STORED and ACCESSED from %APPDATA%\Program name. Optionally, you can use %APPDATA%\Company Name\Program name. One would build a path like this using Path.Combine, something like this:
Code: [Select]String ImageFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"MyGame\Images");
Then you could, for example, use the .NET File access classes to loop through all the files and FIND applicable image files, or you could directory load specific images from those folders, depending on your use case.Thanks you I let you know!
|