2

how to add the string to the resources. So when I restart the program that string should be in the resources. After when I add it how can I get it? For example:

textBox1.Text = // string that I've added;

Thanks...

r.mirzojonov
  • 1,209
  • 10
  • 18
  • Any reason why you prefer to have it as "resource" rather than just a plain text file on disk? – Gray Jun 29 '13 at 11:09
  • 1
    @Gray I don't want any problems with that string. For example when I save it as text file, it can deleted but I don't want that... – r.mirzojonov Jun 29 '13 at 11:11
  • possible duplicate of [How to create and use resources in .NET](http://stackoverflow.com/questions/90697/how-to-create-and-use-resources-in-net) – Gert Arnold Jun 29 '13 at 11:12
  • 1
    Have you taken a look at this? http://stackoverflow.com/questions/5599662/how-do-you-write-to-a-resource-file – Gray Jun 29 '13 at 11:13
  • why you don't use `database` ? – zey Jun 29 '13 at 11:15
  • @zey I don't think it would be good to create database for 1 string – r.mirzojonov Jun 29 '13 at 11:16
  • You can have a text file or xml file and go to file properties in visual studio and set the Buil Action property to "Content" or Embded Resource. so file will eb embded into target assembly, Users cant delete it. – Kurubaran Jun 29 '13 at 11:17

2 Answers2

4

Resources are not the right solution for your problem, they are designed to provide various (language) versions of constant strings. Generating them during execution of the program is possible but not quite easy. Even if you succeed to generate them, saving the file would be also hard - they are stored in the .exe or .dll file, which is probably locked as it is just executing.

Use settings.

Jan Dobkowski
  • 641
  • 3
  • 6
2

Use settings they I've used them for a while and they work great. If you want to change the setting you can do this:

Settings.Default.YourSetting = //Something
Settings.Default.Save();
C-sharper
  • 110
  • 6