Search code examples
c#filevisual-studio-2012installationpublish

Where should i save an ini file?


I have an ini file in my application but where should i save the file and why should i do that? If i use Environment.CurrentDirectory where is the file saved if i publish my application?

I also have an additional question, i hope that's okay. I don't want to create an additional question for that.

If i publish my application how can i create an setup for my application, like the default one, not just this install application windows where you can click install now or not. And where the user could change things like where the application is installed and so on. Where should a ini-File then the be saved or where would it make sense?

If anybody has a useful link or a good tutorial for this it would be nice.

Thanks in Advance


Solution

  • ApplicationData is probably your best bet:

    The directory that serves as a common repository for application-specific data for the current roaming user.

    There's also

    • LocalApplicationData: Current user, non-roaming
    • CommonApplicationData: All users (not specific to any one user)

    Here's how you can get the correct location for storing your file:

    Path.Combine(Environment.GetFolderPath(
        Environment.SpecialFolder.ApplicationData), "yourFile.ini");
    

    As for your second question, I'm not sure what a good setup program would be. It really is a separate question, but as it's asking about a recommendation for a tool, it may be closed.