0

In Visual Studio 2013/2015, when you compile your program exe it saves the config file to its \bin\ folder.

When you move your program exe to a location like C:\Program Files\ and run it, it saves the config file to %appdata% \AppData\Local\.

Using C# or Visual Studio settings, how do I tell the exe to always save the config file to its current folder and not %appdata%?

I want to make the program portable and not use %appdata%.


\bin\ Folder

bin folder


AppData Folder

appdata folder

appdata user config

Matt McManis
  • 4,475
  • 5
  • 38
  • 93
  • How do you "move your program `exe` to a location like `C:\Program Files\`" – praty Jul 25 '17 at 12:59
  • Cut and paste it out of the \bin\release\ folder to C:\Program Files\My Program\. – Matt McManis Jul 25 '17 at 13:01
  • Do you mean to say `config` is automatically created by your exe? I would recommend to publish and install rather than manual copy and paste! `config` files in output directory are created on building the application. So, if you copy you need to copy the config as well. – praty Jul 25 '17 at 13:08
  • When I run the `exe` it automatically creates a `user.config` in `%appdata%`. – Matt McManis Jul 25 '17 at 13:12
  • There must be a code to handle that right? This is not a default action I believe. – praty Jul 25 '17 at 13:15
  • 1
    If you are manually creating a `Configuration` object and calling `Save()` to it, you can set the `FilePath` property of this `Configuration` object to your desired location (to possibly `AssemblyLocation`). – praty Jul 25 '17 at 13:19
  • I believe it's default. I use `Settings.Default.Save();` when saving strings and controls in the program. – Matt McManis Jul 25 '17 at 13:20
  • That's what I need it to do. How do I set `FilePath` property? – Matt McManis Jul 25 '17 at 13:22
  • Ah there you go! This way of saving configs cannot be overriden. It will always save in %appdata%. What could be a work around is you can write a code to read this configuration and create a duplicate configuration with same data. I can you help you with a code which can do that. But, it is just a work around and there is no fix for your actual problem! – praty Jul 25 '17 at 13:33
  • 2
    Possible duplicate of [Custom path of the user.config](https://stackoverflow.com/questions/2265271/custom-path-of-the-user-config) – Bradley Uffner Jul 25 '17 at 13:39
  • @BradleyUffner Thanks, I will look over all of this. – Matt McManis Jul 25 '17 at 13:44

1 Answers1

-2

you can change the output path of your build ...

go to project properties >> build tab >> under output section you can change the output path of your build, so it will creates the build at one place with your all files and make it portable

Ganesh
  • 52
  • 6
  • That's all you need to do? Just keep the original `.exe.config` with it? That's not some kind of temporary config? – Matt McManis Jul 25 '17 at 13:08
  • 1
    you can use build events for that matter : go through the links below https://msdn.microsoft.com/en-us/library/ke5z92ks.aspx <*> https://msdn.microsoft.com/en-us/library/dd293582.aspx – Ganesh Jul 25 '17 at 13:30
  • This only affects the compilation directory, it has absolutely no effect on runtime behavior, or anything else. – Bradley Uffner Jul 25 '17 at 13:36