9

My application is something similar to a Contact Manager. Let's say a user can enter contacts with their addresses. I have the code and technology to save my contacts to a file. But where do I save that file?

Considering this is a .NET application running on Windows. Should my file end up in the AppData of the users folder? Should I use the Isolated Storage (as mentioned here)? Something else? What's the recommended practice?

Aaron McIver
  • 24,527
  • 5
  • 59
  • 88
Peter
  • 13,733
  • 11
  • 75
  • 122
  • If you want your user or other apps to easily find this contacts file, you would want to use AppData. It seems like isolated storage is "too strong" a solution for this particular problem. – Chris O Jan 10 '11 at 18:55
  • I would probably store the information in a database. Is this out of the picture? Otherwise, what benefits will you gain from using one over the other? As far as I know it's basically just two different folders? – Patrick Jan 10 '11 at 19:23
  • @Chris O: in .NET, how can I access the AppData folder? I mean, is there some .NET class which gives me the folder (instead of going to C:\Users\etc hard-coded)? – Peter Jan 10 '11 at 19:27
  • 2
    You get the path to the AppData folder using [Environment.GetFolderPath](http://msdn.microsoft.com/en-us/library/system.environment.getfolderpath.aspx). An example is found in the enum for [SpecialFolder](http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx). – Patrick Jan 11 '11 at 01:42

2 Answers2

9

I ended up using the solution Patrick suggested:

Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Daniel Schilling
  • 4,829
  • 28
  • 60
Peter
  • 13,733
  • 11
  • 75
  • 122
1

You have a number of options; as you say, Isolated Storage is one of them. You could also use the User Settings framework feature and save the data as a blob of data, or as XML.

You could also take a look at SqlCompact for a very lightweight in-process database. You can then save all user contacts in a single database which could live e.g. in the same directory as the application; you could easily use something like EF4 for your DAL.

That might be a bit more effort though, as it sounds like you are 99% of the way there with your current architecture.

Isaac Abraham
  • 3,422
  • 2
  • 23
  • 26
  • Hm, I'm stepping away from a SQL based solution, because it requires too much time and effort (structuring your domain model for an ORM, working with the quirks of an ORM). I'm using Karvonite, which lets me focus on the application itself. – Peter Jan 10 '11 at 19:26
  • Meanwhile, I've switched again :) Now using SterlingDB and Silverlight, so effectively, using Isolated Storage. The project is a little volatile in the beginning. – Peter Feb 29 '12 at 11:32