0

How can I store data on client computers without using data servers?

I have C# Windows app and want to store some data on the user's computer. I don't want to use any type of data server like SQL Server or Access. The user can not read this data and this data is structured like tables with row.

What is the best way to store my data? And how can I handle this case?

Notice that I want to edit and update this data.

All of my data types are string, and I don't want to only store in-memory because after a system reboot the data must still be available for my application to work.

Mark Hildreth
  • 42,023
  • 11
  • 120
  • 109
motevalizadeh
  • 5,244
  • 14
  • 61
  • 108
  • 1
    Is the data supposed to be shared? Should each user have their own set of data? Should the users be able to access the data directly and change it or should that be only through the application? – Oded Sep 11 '12 at 14:50
  • it's not share and each user have their own set of data,should that be only through the application – motevalizadeh Sep 11 '12 at 14:51

5 Answers5

1

Edited for clarity.

There are 2 questions:

  1. Where to store the data? %APPDATA% is a good candidate for application specific data and %UserProfile% for user specific data.
  2. What format and file type should you use? You can store it in many ways, including structured or unstructured formats such as XML, CSV, etc. If you don't want the user to be able to read the content, you can encrypt it in some way. You can also choose to use a local database type, such as SQLCE or SQLLite, which could provide the security you may be looking for.
Szymon Rozga
  • 17,971
  • 7
  • 53
  • 66
  • 1
    If I'm reading his question correctly, he says it shouldn't be human-readable. Xml is very human readable and may not fit his requirements. – Dave Zych Sep 11 '12 at 14:57
  • I guess it could be encrypted if you so wish. I suppose my main point was storing it in the %APPDATA% directory, though really %USERPROFILE% is probably more appropriate. – Szymon Rozga Sep 11 '12 at 15:03
0

You can use XML, its a pretty standard aproach, if you dont want to use DB's.

PS: If you want many users to use the same XML also lock the file on each operation so you will avoid concurency read/write errors.

And a notable advantage is that you can use LinqToXML to perform queries :)

Freeman
  • 5,691
  • 3
  • 29
  • 41
0

You can use SQL Server Compact, it's a DB in a file

or

If you prefer, yo

0

I would suggest using SQL Server Compact which is a lightweight, file based version of a database. Your users do not have to have SQL Server installed to use this option.

This would be my preferred option as it allows you to use LINQ to work with and query the data in the file very easily using technologies such as Entity Framework. In fact you can use POCO's to represent your application entities and Entity Framework will take care of reading and writing the information to the database.

If you are using Entity Framework you can automate the creation of the database using the configuration file. The first time you use any entities the database file will be generated automatically for you (this can be configured).

<configuration>
    <connectionStrings>
        <add name="DatabaseContext"
             providerName="System.Data.SqlServerCe.4.0"
             connectionString="Data Source=C:\Paths\To\Location\DBName.abc"/>
    </connectionStrings>
</configuration>

I would suggest using one of the special folders on the system to make this transparent to the user of your application.

Also notice that you can have whatever extension you want (DBName.abc instead of DBName.sdf) so that the file can be associated with your application.

Using this method also has the advantage that you do not have to load your entire file into memory in one go (I.E. you can query the data and return a subset of the data) which you would not be able to do if you simply serialised your object to a file.

Benjamin Gale
  • 12,977
  • 6
  • 62
  • 100
-1

since it is an windows app, you can create a folder where the app is installed and create MS excel file and save your data in that excel file.

Reza.Hoque
  • 2,690
  • 10
  • 49
  • 78