Question How to store data

mukul2k5

New member
Joined
Jun 17, 2009
Messages
2
Programming Experience
Beginner
HI all,
I want to store some information of the form in such a way that if the user quit/exit the application it stores the information. When user runs the application next time the information should be available to him. It also involve the restart of the computer. The application is in vb.net 3.5 framework.
The one way that i can think of using flat files and encrypted data, but i can not do this. I do not to store any kind of data on client side and I can not store this information on server side. The problem is of getting client machine information and storing it on server.
Help me with a solution. I know it can be done.
Thanks in advance.
 

henryminute

Well-known member
Joined
Jul 24, 2009
Messages
57
Location
UK
Programming Experience
10+
Take a look at Application Settings particularly the section Creating Application Settings at Design Time which will tell you, or at least link to, how to store and restore Form.Size, Form.Location and the like.

The section below Using Custom Settings Files might help if the above gives you problems.

Hope this helps. :)
 

Tom

Well-known member
Joined
Aug 23, 2005
Messages
746
Programming Experience
5-10
I like flat files the best for simple data. This way a seperate file can be created for each individual user. Is there a limiting factor that you "can not do this" or do you just not know how? Storing it to a centralized database is also an option but again you mention not being able to do this....

Application Settings seems to be another option but may may not be as flexible as needed. The settings are then saved per application level and there may be multiple users per application workstation and/or the possibility of the application running from a shared network drive.
 

henryminute

Well-known member
Joined
Jul 24, 2009
Messages
57
Location
UK
Programming Experience
10+
ApplicationSettings is badly named as it deals with both Application-wide and per-user settings.

The code snippet below is the *.exe.config file from an application on my machine.

I have highlighted a section in red.
Note that the node is 'usersettings' and this part will be stored for each user.
Where it is stored depends on how the network is set up. It uses Local Settings\Application Data on my standalone. This is governed by the Environment.SpecialFolder enumeration, the first three members are of interest here, and as I say how your network is set up.

I created this section in the *.config file with the following steps
1) Select Form in designer (could have selected a Button, Panel or whatever)
2) Under (ApplicationSettings), in the Property Grid, click the ellipsis on (PropertyBinding)
3) Select the property required from the Dialog that appears and click the drop-down, then click the (New...) link.
4) In the Dialog that appears give the setting a name and you can choose whether it is scoped for user or application.
5) OK your way out.

VB.NET:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="TelephoneNumberWordGenerator.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <system.diagnostics>
        <sources>
            <!-- This section defines the logging configuration for My.Application.Log -->
            <source name="DefaultSource" switchName="DefaultSwitch">
                <listeners>
                    <add name="FileLog"/>
                    <!-- Uncomment the below section to write to the Application Event Log -->
                    <!--<add name="EventLog"/>-->
                </listeners>
            </source>
        </sources>
        <switches>
            <add name="DefaultSwitch" value="Information" />
        </switches>
        <sharedListeners>
            <add name="FileLog"
                 type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
                 initializeData="FileLogWriter"/>
            <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
            <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
        </sharedListeners>
    </system.diagnostics>
[B][COLOR="Red"]   <userSettings>
        <TelephoneNumberWordGenerator.My.MySettings>
            <setting name="MainformBorder" serializeAs="String">
                <value>Sizable</value>
            </setting>
        </TelephoneNumberWordGenerator.My.MySettings>
    </userSettings>[/COLOR][/B]
</configuration>

Do a small test for yourself. Either with an existing app or create a very simple one specially for the test. Create one or two user scoped settings (say Form.Size and Form.Location). Then have two users run the app, one user uses left and tall, the other right and wide. Close the app and restart it. They should both get what they set before closing.

So the solution could be to do as above for applicable settings and use your flat file methodology for whatever doesn't fit. However bear in mind that you can use the My.Settings for those parts too, where you can also elect for user or application scoping.

Hope this helps. :)
 
Top Bottom