Results 1 to 11 of 11

Thread: User.Config location

  1. #1

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    User.Config location

    OK, so, the My.Settings data is saved in the AppData\Local folder for a user based on company.
    Then, inside the company folder there will be a folder for any applications published by that company, which contain the user.config file for that program.

    C:\Documents and Settings\Robert Burke\Local Settings\Application Data\Serysoft\SysPad.exe_Url_qr40iotmbi1lvvl4b5lecnfpoqogr5uw

    The thing is, the folder for each program has a string of random alphanumeric characters at the end. I noticed that on both my XP and Win7 machine, the string is the same. What I am wanting to do is save the user.config file, but the only way to do this, seemingly, would be to hardcode that folder into the path to get the user.config file from.

    My question is wondering how that string is generated, and what may possibly cause it to change in other releases even though, so far, it has stayed the same for several of my releases. I don't want to release a version one day and the string change and then it break my program.

    Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7

    SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
    [Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]

    [.NET and MySQL Quick Guide]

  2. #2
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: User.Config location

    I don't know why you want the file name for - I wanted the data to be more user friendly in the settings in my app so i did it the following way - this kinda overrules (i didn't want to say override) the framework method ... their config file exists too ... but this has priority - you can also put it where you want

    Hope it helps

    vb Code:
    1. Imports System.Xml.Serialization
    2. Imports System.IO
    3.  
    4. Namespace AppSettings
    5.  
    6.     <Serializable()> _
    7.     Public Class clsSettings
    8.         Public Setting As New Generic.List(Of clsSetting)
    9.  
    10.         <Serializable()> _
    11.         Public Class clsSetting
    12.             Public Key As String
    13.             Public Value As Object
    14.         End Class
    15.     End Class
    16.  
    17.     <Serializable()> _
    18.     Public Class sFont
    19.         Public FontName As String
    20.         Public Size As Single
    21.         Public Style As Integer
    22.     End Class
    23.  
    24.     <Serializable()> _
    25.     Public Class sColor
    26.         Public A As Byte
    27.         Public R As Byte
    28.         Public G As Byte
    29.         Public B As Byte
    30.     End Class
    31.  
    32. End Namespace
    33.  
    34. Namespace My
    35.  
    36.     Partial Friend NotInheritable Class MySettings
    37.         Inherits Global.System.Configuration.ApplicationSettingsBase
    38.  
    39.         Public Sub userOverride_SettingsLoaded(ByVal sender As Object, _
    40.                 ByVal e As System.Configuration.SettingsLoadedEventArgs) _
    41.             Handles Me.SettingsLoaded
    42.             If FileIO.FileSystem.FileExists("Files\Settings.txt") Then
    43.                 Try
    44.  
    45.                     Dim deser As XmlSerializer = New XmlSerializer(GetType(AppSettings.clsSettings), New Type() {GetType(Color), GetType(System.Drawing.Size)})
    46.                     Dim streamrd As New StreamReader("Files\Settings.txt")
    47.                     Dim clsSettings As AppSettings.clsSettings
    48.                     clsSettings = deser.Deserialize(streamrd)
    49.                     streamrd.Close()
    50.  
    51.                     For Each Item As AppSettings.clsSettings.clsSetting In clsSettings.Setting
    52.                         Try
    53.                             If TypeOf Item.Value Is System.Array Then
    54.                                 If TypeOf Item.Value(0) Is System.Xml.XmlAttribute Then
    55.                                     Dim ValueType As System.Xml.XmlAttribute = Item.Value(0)
    56.                                     Select Case ValueType.Value
    57.                                         Case "sColor"
    58.                                             Dim sColor As Color = Color.FromArgb(Item.Value(1).innertext, Item.Value(2).innertext, Item.Value(3).innertext, Item.Value(4).innertext)
    59.                                             Me(Item.Key) = sColor
    60.                                         Case "sFont"
    61.                                             Dim FS As FontStyle = Item.Value(3).innertext
    62.                                             Dim sFont As New Font(CStr(Item.Value(1).innertext), CSng(Item.Value(2).innertext), FS)
    63.                                             Me(Item.Key) = sFont
    64.  
    65.                                     End Select
    66.                                 End If
    67.                             Else
    68.                                 Me(Item.Key) = Item.Value
    69.                             End If
    70.                         Catch ex As Exception
    71.  
    72.                         End Try
    73.                     Next
    74.                 Catch ex As Exception
    75.  
    76.                 End Try
    77.             End If
    78.  
    79.         End Sub
    80.  
    81.         Private Sub userOverride_SettingsSaving(ByVal sender As Object, _
    82.                 ByVal e As System.ComponentModel.CancelEventArgs) _
    83.             Handles Me.SettingsSaving
    84.             FileIO.FileSystem.CreateDirectory("Files")
    85.  
    86.  
    87.             Dim clssettings As New AppSettings.clsSettings
    88.  
    89.             For Each appProperty As System.Configuration.SettingsProperty In My.Settings.Properties
    90.                 Dim clsSetting As New AppSettings.clsSettings.clsSetting
    91.                 clsSetting.Key = appProperty.Name
    92.                 If TypeOf Me(appProperty.Name) Is Font Then
    93.                     Dim OrigValue As Font = Me(appProperty.Name)
    94.                     Dim ValueItem As New AppSettings.sFont
    95.                     ValueItem.FontName = OrigValue.OriginalFontName
    96.                     ValueItem.Style = OrigValue.Style
    97.                     ValueItem.Size = OrigValue.Size
    98.                     clsSetting.Value = ValueItem
    99.                 ElseIf TypeOf Me(appProperty.Name) Is Color Then
    100.                     Dim OrigValue As Color = Me(appProperty.Name)
    101.                     Dim ValueItem As New AppSettings.sColor
    102.                     ValueItem.A = OrigValue.A
    103.                     ValueItem.R = OrigValue.R
    104.                     ValueItem.G = OrigValue.G
    105.                     ValueItem.B = OrigValue.B
    106.                     clsSetting.Value = ValueItem
    107.                 Else
    108.                     clsSetting.Value = Me(appProperty.Name)
    109.                 End If
    110.                 clssettings.Setting.Add(clsSetting)
    111.             Next
    112.             Dim serializer As XmlSerializer = New XmlSerializer(GetType(AppSettings.clsSettings), New Type() {GetType(Color), GetType(System.Drawing.Size), GetType(AppSettings.sFont), GetType(AppSettings.sColor)})
    113.             Dim tw As TextWriter = New StreamWriter("Files\Settings.txt")
    114.             serializer.Serialize(tw, clssettings)
    115.             tw.Close()
    116.  
    117.         End Sub
    118.     End Class
    119. End Namespace

    Kris

  3. #3
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: User.Config location

    btw to use the above just put it in a new class file ... and it will do the rest - you will then notice a Files\Settings.txt file creates when the settings are saved - this is used instead of the app config file

    Kris

  4. #4

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    Re: User.Config location

    So this means I have to customize it for my settings?
    I just want the user.config file so that if a person wants to backup their settings, with the backup feature i have in the program, I can just program it to grab this along with a few other files I have it currently backing up.

    Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7

    SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
    [Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]

    [.NET and MySQL Quick Guide]

  5. #5
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: User.Config location

    just backup the "Files\settings.txt" and take it with you - another reason i did it this way -and like i said can make this app put it in another folder like the documents folder of each user to make it user specific if you want.

  6. #6
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: User.Config location

    You can always use the "Settings.Setting" component.
    (Add new Item > General > Settings File)
    Easy to backup


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: User.Config location

    Hey,

    You can easily find the User's Settings file, all you have to do is use some of the built in keywords that help you access special system folders.

    You can find information about this here:

    http://www.codeproject.com/KB/vb/appsettings2005.aspx

    Hope that helps!!

    Gary

  8. #8
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: User.Config location

    Using the application.settings is "harder" to backup, 'cause the settings are written into the registry. The Settings.Settings file is one file you can find in the application.startuppath.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  9. #9

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    Re: User.Config location

    My question was what are the chances of the hash in that folder changing?
    I want to save user.config because that is what is generated by My.Settings.
    That question has yet to be addressed, which is all I really wanted to know; where does that hash come form and can it change randomly.
    Don't see a point in going through the trouble of making my own settings file when I can just work with the one My.Settings creates if possible.


    i00: I asked you if I would have to customize that code you gave me to work with all my settings. It looks like I would have to but I want to be sure.

    Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7

    SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
    [Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]

    [.NET and MySQL Quick Guide]

  10. #10
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Re: User.Config location

    My.Settings works the same as the Settings.Settings-File, but the easy part of the Settings.File is that all your settings are located in a small file and you don't have to export registry settings, what you have to do when using the my.settings.

    Both times you have to created it yourself by the way. So it ain't extra work.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  11. #11
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,390

    Re: User.Config location

    mine requires you to put it in your project and it automatically goes off the settings that you have specified in your project properties - so no customization is required for basic data - because it uses xml serialization certain types cannot be serialized such as font - that is why I have created a class called sFont (etc) that hold the data then these serialize

    Kris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width