Home All Groups Group Topic Archive Search About

How to reset Windows Application's default programmatically?

Author
20 Sep 2006 5:09 PM
Nina
Hi Everyone,

I have made a windows application using vb.net 2003.   When user opens this
application it will display a default location in a textbox.  This
application has to allow user to change the default location and set their
desired location as application’s new default. For instance, if the
application’s default location is Chicago, every time user launches this
program Chicago will be displayed in the textbox.  If user changes the
default location to Toronto, then click a button to set Toronto as default. 
Later when user opens this application again, it should display Toronto
instead of Chicago.  How can I achieve this?  Please help.

Thank you in advance.

Nina

Author
20 Sep 2006 5:21 PM
IdleBrain
Hey Nina,
You might want to use windows registry to do this.
Use SaveSetting() to store the setting into registry and GetSetting to
retreive it back.

Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
store after user selects a different city.

Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
"City", "DefaultValue") when you load the form to fill up the textbox

Hope it helps.
Author
20 Sep 2006 6:14 PM
rowe_newsgroups
Another option is to use XML files. Check out  the XML document object
model. Be warned that this approach is more difficult to set up and
requires more code to use. Just throwing in my 2 cents :-)

Thanks,

Seth Rowe

IdleBrain wrote:
Show quoteHide quote
> Hey Nina,
> You might want to use windows registry to do this.
> Use SaveSetting() to store the setting into registry and GetSetting to
> retreive it back.
>
> Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
> store after user selects a different city.
>
> Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
> "City", "DefaultValue") when you load the form to fill up the textbox
>
> Hope it helps.
Author
20 Sep 2006 6:54 PM
Izzy
I agree with rowe_newsgroups, XML is how I would do it.

Using XML isn't hard either. I use the code below to do exactly this.

Private Sub LoadSettings()

        Dim dsSettings as new Dataset
        Dim dtSettings as Datatable
        Dim SettingsPath As String = Application.StartupPath & "\" &
My.Settings.ServerSettingsFile

        dsSettings.DataSetName = "ServerSettings"

        If IO.File.Exists(SettingsPath) Then
            dsSettings.ReadXml(SettingsPath)
            dtSettings = dsSettings.Tables("HardDriveSettings")

        Else

            Dim dcSN As New DataColumn 'Server Name
            Dim dcDTM As New DataColumn 'Drive to monitor.
            Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
            Dim drSettings As DataRow

            dcSN.ColumnName = "ServerName"
            dcSN.DataType = GetType(System.String)
            dcDTM.ColumnName = "DriveLeter"
            dcDTM.DataType = GetType(System.String)
            dcFSTH.ColumnName = "FreeSpaceThreshHold"
            dcFSTH.DataType = GetType(System.Int32)

            dtSettings = New DataTable
            dtSettings.TableName = "HardDriveSettings"

            dtSettings.Columns.Add(dcSN)
            dtSettings.Columns.Add(dcDTM)
            dtSettings.Columns.Add(dcFSTH)

            drSettings = dtSettings.NewRow
            drSettings(0) = "stc-dc"
            drSettings(1) = "D:"
            drSettings(2) = 15
            dtSettings.Rows.Add(drSettings)

        End If

    End Sub

In the above example I created a settings file for a program which
monitors hard drive space on production servers. Using XML to store the
list of servers to be monitored along with the dirve letter and free
space setting.

In your case after you load the settings using dsSettings.ReadXml(Path)
and after your users make a change you would then call
dsSettings.WriteXml(Path) to write the change to disk.

Izzy

rowe_newsgroups wrote:
Show quoteHide quote
> Another option is to use XML files. Check out  the XML document object
> model. Be warned that this approach is more difficult to set up and
> requires more code to use. Just throwing in my 2 cents :-)
>
> Thanks,
>
> Seth Rowe
>
> IdleBrain wrote:
> > Hey Nina,
> > You might want to use windows registry to do this.
> > Use SaveSetting() to store the setting into registry and GetSetting to
> > retreive it back.
> >
> > Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
> > store after user selects a different city.
> >
> > Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
> > "City", "DefaultValue") when you load the form to fill up the textbox
> >
> > Hope it helps.
Author
20 Sep 2006 6:57 PM
Izzy
I agree with rowe_newsgroups, XML is how I would do it.

Using XML isn't hard either. I use the code below to do exactly this.

Private Sub LoadSettings()

        Dim dsSettings as new Dataset
        Dim dtSettings as Datatable
        Dim SettingsPath As String = Application.StartupPath & "\" &
My.Settings.ServerSettingsFile

        dsSettings.DataSetName = "ServerSettings"

        If IO.File.Exists(SettingsPath) Then
            dsSettings.ReadXml(SettingsPath)
            dtSettings = dsSettings.Tables("HardDriveSettings")

        Else

            Dim dcSN As New DataColumn 'Server Name
            Dim dcDTM As New DataColumn 'Drive to monitor.
            Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
            Dim drSettings As DataRow

            dcSN.ColumnName = "ServerName"
            dcSN.DataType = GetType(System.String)
            dcDTM.ColumnName = "DriveLeter"
            dcDTM.DataType = GetType(System.String)
            dcFSTH.ColumnName = "FreeSpaceThreshHold"
            dcFSTH.DataType = GetType(System.Int32)

            dtSettings = New DataTable
            dtSettings.TableName = "HardDriveSettings"

            dtSettings.Columns.Add(dcSN)
            dtSettings.Columns.Add(dcDTM)
            dtSettings.Columns.Add(dcFSTH)

            drSettings = dtSettings.NewRow
            drSettings(0) = "stc-dc"
            drSettings(1) = "D:"
            drSettings(2) = 15
            dtSettings.Rows.Add(drSettings)

        End If

    End Sub

In the above example I created a settings file for a program which
monitors hard drive space on production servers. Using XML to store the
list of servers to be monitored along with the dirve letter and free
space setting.

In your case after you load the settings using dsSettings.ReadXml(Path)
and after your users make a change you would then call
dsSettings.WriteXml(Path) to write the change to disk.

Izzy

rowe_newsgroups wrote:
Show quoteHide quote
> Another option is to use XML files. Check out  the XML document object
> model. Be warned that this approach is more difficult to set up and
> requires more code to use. Just throwing in my 2 cents :-)
>
> Thanks,
>
> Seth Rowe
>
> IdleBrain wrote:
> > Hey Nina,
> > You might want to use windows registry to do this.
> > Use SaveSetting() to store the setting into registry and GetSetting to
> > retreive it back.
> >
> > Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
> > store after user selects a different city.
> >
> > Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
> > "City", "DefaultValue") when you load the form to fill up the textbox
> >
> > Hope it helps.
Author
21 Sep 2006 1:30 PM
Nina
Thank you IdleBrain, rowe_newsgroups, and Izzy for all your help.  Now I know
where to start.  Have a nice day!

Nina

Show quoteHide quote
"Izzy" wrote:

> I agree with rowe_newsgroups, XML is how I would do it.
>
> Using XML isn't hard either. I use the code below to do exactly this.
>
> Private Sub LoadSettings()
>
>         Dim dsSettings as new Dataset
>         Dim dtSettings as Datatable
>         Dim SettingsPath As String = Application.StartupPath & "\" &
> My.Settings.ServerSettingsFile
>
>         dsSettings.DataSetName = "ServerSettings"
>
>         If IO.File.Exists(SettingsPath) Then
>             dsSettings.ReadXml(SettingsPath)
>             dtSettings = dsSettings.Tables("HardDriveSettings")
>
>         Else
>
>             Dim dcSN As New DataColumn 'Server Name
>             Dim dcDTM As New DataColumn 'Drive to monitor.
>             Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
>             Dim drSettings As DataRow
>
>             dcSN.ColumnName = "ServerName"
>             dcSN.DataType = GetType(System.String)
>             dcDTM.ColumnName = "DriveLeter"
>             dcDTM.DataType = GetType(System.String)
>             dcFSTH.ColumnName = "FreeSpaceThreshHold"
>             dcFSTH.DataType = GetType(System.Int32)
>
>             dtSettings = New DataTable
>             dtSettings.TableName = "HardDriveSettings"
>
>             dtSettings.Columns.Add(dcSN)
>             dtSettings.Columns.Add(dcDTM)
>             dtSettings.Columns.Add(dcFSTH)
>
>             drSettings = dtSettings.NewRow
>             drSettings(0) = "stc-dc"
>             drSettings(1) = "D:"
>             drSettings(2) = 15
>             dtSettings.Rows.Add(drSettings)
>
>         End If
>
>     End Sub
>
> In the above example I created a settings file for a program which
> monitors hard drive space on production servers. Using XML to store the
> list of servers to be monitored along with the dirve letter and free
> space setting.
>
> In your case after you load the settings using dsSettings.ReadXml(Path)
> and after your users make a change you would then call
> dsSettings.WriteXml(Path) to write the change to disk.
>
> Izzy
>
> rowe_newsgroups wrote:
> > Another option is to use XML files. Check out  the XML document object
> > model. Be warned that this approach is more difficult to set up and
> > requires more code to use. Just throwing in my 2 cents :-)
> >
> > Thanks,
> >
> > Seth Rowe
> >
> > IdleBrain wrote:
> > > Hey Nina,
> > > You might want to use windows registry to do this.
> > > Use SaveSetting() to store the setting into registry and GetSetting to
> > > retreive it back.
> > >
> > > Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago") to
> > > store after user selects a different city.
> > >
> > > Use txtboxCityName.text = GetSetting("ApplicationName", "FolderName",
> > > "City", "DefaultValue") when you load the form to fill up the textbox
> > >
> > > Hope it helps.
>
>
Author
21 Sep 2006 7:08 PM
GhostInAK
Hello Izzy,

I don't like this approach.  Datasets dont feel right for storing application
settings.  A custom object would be a better approach.  It feels better.
It also allows your settings to take advantage of strongly typed data, and
intellisense within the IDE.

-Boo

Show quoteHide quote
> I agree with rowe_newsgroups, XML is how I would do it.
>
> Using XML isn't hard either. I use the code below to do exactly this.
>
> Private Sub LoadSettings()
>
> Dim dsSettings as new Dataset
> Dim dtSettings as Datatable
> Dim SettingsPath As String = Application.StartupPath & "\" &
> My.Settings.ServerSettingsFile
> dsSettings.DataSetName = "ServerSettings"
>
> If IO.File.Exists(SettingsPath) Then
> dsSettings.ReadXml(SettingsPath)
> dtSettings = dsSettings.Tables("HardDriveSettings")
> Else
>
> Dim dcSN As New DataColumn 'Server Name
> Dim dcDTM As New DataColumn 'Drive to monitor.
> Dim dcFSTH As New DataColumn 'Free Space Threshhold in GBs
> Dim drSettings As DataRow
> dcSN.ColumnName = "ServerName"
> dcSN.DataType = GetType(System.String)
> dcDTM.ColumnName = "DriveLeter"
> dcDTM.DataType = GetType(System.String)
> dcFSTH.ColumnName = "FreeSpaceThreshHold"
> dcFSTH.DataType = GetType(System.Int32)
> dtSettings = New DataTable
> dtSettings.TableName = "HardDriveSettings"
> dtSettings.Columns.Add(dcSN)
> dtSettings.Columns.Add(dcDTM)
> dtSettings.Columns.Add(dcFSTH)
> drSettings = dtSettings.NewRow
> drSettings(0) = "stc-dc"
> drSettings(1) = "D:"
> drSettings(2) = 15
> dtSettings.Rows.Add(drSettings)
> End If
>
> End Sub
>
> In the above example I created a settings file for a program which
> monitors hard drive space on production servers. Using XML to store
> the list of servers to be monitored along with the dirve letter and
> free space setting.
>
> In your case after you load the settings using
> dsSettings.ReadXml(Path) and after your users make a change you would
> then call dsSettings.WriteXml(Path) to write the change to disk.
>
> Izzy
>
> rowe_newsgroups wrote:
>
>> Another option is to use XML files. Check out  the XML document
>> object model. Be warned that this approach is more difficult to set
>> up and requires more code to use. Just throwing in my 2 cents :-)
>>
>> Thanks,
>>
>> Seth Rowe
>>
>> IdleBrain wrote:
>>
>>> Hey Nina,
>>> You might want to use windows registry to do this.
>>> Use SaveSetting() to store the setting into registry and GetSetting
>>> to
>>> retreive it back.
>>> Use SaveSetting("ApplicationName", "FolderName", "City", "Chicago")
>>> to store after user selects a different city.
>>>
>>> Use txtboxCityName.text = GetSetting("ApplicationName",
>>> "FolderName", "City", "DefaultValue") when you load the form to fill
>>> up the textbox
>>>
>>> Hope it helps.
>>>