3

So for example, when I load word, if I go to save a file, it will default to the same directory that I selected last time...Also, it keeps track of the last 10 (or whatever) .doc files you opened

how does it do this? Right now for a program I am writing (in C#), I just save a text document which holds these kinds of settings...is this bad practice??

If not, where should I put this text doc. Right now I am just using:

 Path.GetDirectoryName(Application.ExecutablePath);

as the directory where this file is held...its fine before I publish the program, because it just uses one of the folders in the solution directory...

But after I publish it, the directory is really weird:

C:\users\me\AppData\Local\Apps\2.0\J6AAL16C.2QW.....

and it goes on....So is this like a directory created for this program when I install it?? is this where it SHOULD be getting saved?

Thanks!!

Toadums
  • 2,772
  • 8
  • 44
  • 67
  • Use registry for persisting the settings. – Dimitri Jun 17 '11 at 16:35
  • When it comes to this stuff, I know literally nothing...could you elaborate? :) – Toadums Jun 17 '11 at 16:38
  • 2
    whatever you do don't put it in the same folder as your exe since you may not have write access to that location – David Heffernan Jun 17 '11 at 16:47
  • 1
    I agree with Jon's answer below. Avoid the registry if you don't have a compelling reason to use it. Generally, I use the app.config file and then build a class around that (App.cs) with read-only, typed properties so that I don't have to worry about nulls and key name spelling errors. – Jemes Jun 17 '11 at 16:53

1 Answers1

3

The Application Settings feature of .NET makes this pretty simple, really. In particular I wouldn't use the registry if I were you - it makes it harder for users to copy settings from machine to machine, etc.

It does get a bit weird if you try writing your own settings providers though - I've tried to understand the overall design a couple of times, and always got lost. For simple applications though, it's easy.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • mmm, what do you mean by settings provider? I am just using a deliminated text file... – Toadums Jun 17 '11 at 16:50
  • @Toadums: Using the built-in .NET features, you won't need to write or read the file yourself at all. It'll be done for you. If you *want* to control the format etc, that's when it gets complicated. – Jon Skeet Jun 17 '11 at 16:51
  • According to http://stackoverflow.com/questions/2518772/how-to-change-net-user-settings-location you can't even change the storage location with the default provider. Makes the default provider pretty useless IMO, since then it can't even support portable applications. – CodesInChaos Jun 17 '11 at 16:57
  • @CodeInChaos: Well, not supporting portable applications isn't the same as useless, IMO. Not every application needs to be portable, even though for *some* apps it's very useful. – Jon Skeet Jun 17 '11 at 16:59
  • I dont know what portable means, but I dont think mine needs to be it lol...I will go over the Application Settings and see if I can understand anything in it...I am pretty bad at understanding the msdn "api" (?) Thanks!! – Toadums Jun 17 '11 at 18:46