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.

Is it possible to use OpenFileDialog in XNA 4.0 to get the file path? If not, what is the alternative? I'm using XNA 4.0 to create a graphic display (not a game) and I have a file that contains informations on how and what to draw on screen. The only problem is that I hard-coded the path because I don't know how to dynamically get that path? Do you know a solution for that?

share|improve this question
2  
Have you seen the XNA with WinForms examples on the App Hub? Links are in this answer: stackoverflow.com/a/6558501/593627 –  George Duckett Apr 27 '12 at 10:15
    
No I haven't, thanks for the link, I'll take a look when I get the time. –  NDraskovic Apr 27 '12 at 10:19
    
You can put the information in an XML file, have it build as content and then load it in game the same you load textures and models. Only problem is that you can't change it then without rebuilding. You can also give it the path relative from your .exe (on PC) using a new Uri(...) with the Relative option set. –  Roy T. Apr 27 '12 at 10:26
    
I know about the XML approach but I can't use it because the application will be used on multiple computers (that is the root of the problem) so I need to be able to change the data after building –  NDraskovic Apr 27 '12 at 10:29
    
Are you aware of relative paths? I think what you are describing is that you are using absolute file system path to access a file located in your application's folder when you could just access it for example ".\myfile" or just "myfile". Besides that, yes, .net has OpenFileDialog class and you could use it to allow user select a file... –  Toni Apr 27 '12 at 10:57
show 4 more comments

1 Answer

up vote 5 down vote accepted

Just put the Attribute [STAThread] above the Main method in the class Program and add the System.Windows.Forms in the References of the project.

After that you'll be able to instantiate and invoke the dialog boxes.

share|improve this answer
add comment

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.