0

I have a simple string variable and I want to save the value when starting application, the application is a standalone and I don't want to use registery. I tried to put the string as settings but it saved in a app.config file.

can I save a variable in the self application?

Bjørn-Roger Kringsjå
  • 9,849
  • 6
  • 36
  • 64
  • 4
    You can't save it in to the EXE file. You need to save it in some other file, like "app.config", text file, or a database of some sort. – Enigmativity Dec 27 '15 at 10:55

1 Answers1

0

What I usually do is save the string in a text file like this:

var stringToSave = "MyString";
var filePath = Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData) + "\\YourApplicationName\\data.dat";

using (StreamWriter sw = new StreamWriter (filePath)) {
    sw.WriteLine (stringToSave);
}

What I am doing here is basically getting the directory of AppData and writes a file called data.dat in there. It should be pretty self-explanatory.

Sweeper
  • 213,210
  • 22
  • 193
  • 313