Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I made a "game" for a college project that reads data from .txt file at startup and draws some models according to the data in that file. This is the code I use

using (StreamReader sr = new StreamReader(@"C:\Users\User\Desktop\Linije.txt"))                
                {
                    String linija;                    
                    while ((linija = sr.ReadLine()) != null)
                    {
                        red = linija.Split(',');                          
                        model = red[0];
                        x = red[1];
                        y = red[2];
                        z = red[3];
                        elementi.Add(Convert.ToInt32(model));
                        podatci.Add(new Vector3(Convert.ToSingle(x),Convert.ToSingle(y),Convert.ToSingle(z)));
                    }
                }

As you see, this code fills some variables that are then used to define the model that will be drawn and the coordinates where it will be drawn. The problem that I'm having is that I don't know how to distribute that file to other computers (obviously on another computer it would have another path)? Do you have some advices on how to do this? P.S I tried to put it in the Content and set the Build Action on None, and I can see the file in the content directory, but when I change it, nothing happens (the models don't change as they should)

share|improve this question
    
stackoverflow.com/questions/52797/… –  James Apr 16 '12 at 8:20
1  
The above link shows you how to get the path to where the exe that is running is currently located. You can then just put the txt file in the same folder or a sub folder from the EXE.. I did not post this as an answer as it seems odd when its just a link to another answer. (Sorry for the double comments. I hit enter when I did not mean to.) –  James Apr 16 '12 at 8:22

1 Answer 1

up vote 0 down vote accepted

if you just want to put the file in the same directory as the exe, you can simply write:

using (StreamReader sr = new StreamReader("Linije.txt"))  
share|improve this answer
    
I tried, the file does not show in the directory, although I placed the "Copy to Output directory" to "Copy always" –  NDraskovic Apr 16 '12 at 8:58
    
It's probably in the Content folder. Open your project's folder in Windows Explorer (it's on the right-click menu) and navigate into `\bin\x86\Debug`. Your compiled project and all its stuff is inside there (plus some .pdb files which are debug files, and not required for redistributing the game). There might be subfolders like a Content folder which will probably contain your file. –  doppelgreener Apr 16 '12 at 9:12
    
you have to manually copy the file to the same directory as the exe... if you want the solution with copy to OutputDir you can write: StreamReader reader = new StreamReader("Content" + Path.DirectorySeparatorChar + "Linije.txt"); –  Saikai Apr 16 '12 at 9:16
    
Instead of copying files, either change the working directory of the executable used when running in the debugger, or detect when running in the debug output directory and look up into the project's root directory for content files. Copying files is completely unworkable when you have lots of or large content files, and can cause a few other interesting problems (e.g., if you scan all content files, then left-over files from a previous copy after deleting one of them can be problematic). –  Sean Middleditch Apr 16 '12 at 9:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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