Results 1 to 14 of 14

Thread: [RESOLVED]Adding Property to My.Settings @ runtime

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Resolved [RESOLVED]Adding Property to My.Settings @ runtime

    This is the code...

    VB Code:
    1. Dim prop As System.Configuration.SettingsProperty = New System.Configuration.SettingsProperty(TreeView1.SelectedNode.Parent.ToString)
    2. My.Settings.Properties.Add(prop)
    3. My.Settings.Save()

    The problem is that the property isnt added to the Settings. Does anyone know how to add a Property to the user settings?

    Thanx, Figa
    Last edited by figa; Aug 28th, 2006 at 05:26 PM.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Adding Property to My.Settings @ runtime

    How do you know it's not being added?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: Adding Property to My.Settings @ runtime

    If i go to the project properties, then to the settings window, i can see its not being added...

  4. #4
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: Adding Property to My.Settings @ runtime

    you do realize that you won't see anything added to that when you run the application because the settings file that you'd be looking at isn't the same one

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  5. #5
    Frenzied Member vbdotnetboy's Avatar
    Join Date
    Jun 2004
    Location
    Lewisburg, PA "Next year Raiders in the Super Bowl"
    Posts
    1,310

    Re: Adding Property to My.Settings @ runtime

    for instance here is the path of the settings file for a project i'm working on is
    C:\Documents and Settings\dklingman\Application Data\CSSI\EmailPollingService.vshos_Url_yugefftfbxq401mle51pngzdbyfsghsm\1.0.0.55

    that's where the file is located durning runtime

    Derek - Using VS 2008 99% of the time and VS 2003 1% of the time

    Please Help Us To Save Ana

    ● Helpful Links: DNR TV | Awesome site for tips | Using ADO.NET to work with Excel | Xml Namespace 2.0 Framework Changes|Ultra High Security Password Generator | Mendhak's ADO.NET Tutorial
    ● Code Bank: Random Password Generator | Generic DbProviderFactory Access
    ● Site Work: Bottle Run Xtreme | Spaids Racing.com

    Company I work for - CSSI

    WHEN POSTING PLEASE INDICATE VERSION

    Please use vbcode tags or code tags when posting code
    [highlight=vb]ALL your code goes here[/highlight] or [code]ALL your code goes here[/code]

    If my post helped you in anyway... please be kind and give me some ratings

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: Adding Property to My.Settings @ runtime

    Hi, do you have a small piece of code about adding and saving settings?

    Thanx

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Adding Property to My.Settings @ runtime

    Here's what you have to realize.... the code it right.... the property is being added.... BUT... when you look at the Project Properties... it reads its values from the App.Config that is in the project root folder. But that's not the file that actualy gets read during runtime.... If you look in the bin folder... you should see a applicationname.exe.config file... THAT is the config file during run-time. Now here's the kicker... if you make changes to the app.config in the project root.... and run your applicaiton, the newer app.confg file will OVERWRITE the older appname.exe.config file. That means you will lose anything that is in the appname.exe.config file.

    -tg

    OG Tay sez: yo!
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: Adding Property to My.Settings @ runtime

    (I just read your post again, and i think you just described what im saying . Is there a workaround ?)


    But it will overwrite with the old not changed data right..? So nothing is lost.

    I just want to add some setting i want to save give it a value and save it. Now i can add a property on runtime, if i count it it all went right, but when i start my program again, the new property is gone...

    Ill be back late, i appreciate the help, but im no longer online. Anyway thanx, and if i dont forget ill post the answer.

    Figa

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Adding Property to My.Settings @ runtime

    The workaround it to add it in design time from the start....but that doesn't sound like what you want.

    The reason the property is gone the next time you run it is because the IDE takes the app.config file and copies it to the bin folder when you run your app. After running your app, if you "Show All Files" ... look in the bin directory. You should see a file appname.vshost.exe.config.... open it up.... look in there, you;ll find the settings for your added property. But the next time you run your app, that file will get overritten by the file that is in your project's root folder... making it appear to be gone.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Adding Property to My.Settings @ runtime

    This is ridiculous. There is no workaround because there is no problem. Your code is working exactly as it should be. If you're recompiling your project over and over then of course you're losing the changes you're making at run time. When your app is deployed though, you won't be recompiling each time the app is run so any changes you make will be permanent. If you want to prove to yourself that this is the case then compile a Release build and run it a couple of times directly from Windows Explorer. You'll see that any changes you make will be persisted to the next session.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: Adding Property to My.Settings @ runtime

    Thanx for the info, but this way the User and Application mode arent that different. Ill will make my own settings file then, thanks.

    Figa

    (just read your post jim, is there a way that i can see in it saves in my enviroment?)
    Last edited by figa; Aug 28th, 2006 at 05:31 PM.

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED]Adding Property to My.Settings @ runtime

    *Sigh* .... figa - you hear us, but you're not listening.... it's the way it works... that's just the way it is. As long as you continue to run the app in the IDE, the config file will be OVERWRITTEN every time... there is NO workaorund, because as jmc said, there is no problem. Your code is working. I don't know what else we can tell you.

    -tg

    OG Tay sez: Duuuude! Sweeeeet!
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    198

    Re: [RESOLVED]Adding Property to My.Settings @ runtime

    Well then, thats just lame....So i have to make a redistubutable everytime i want to see if its stores the right value...that sucks, but thanks

    We're done

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED]Adding Property to My.Settings @ runtime

    Arrrgh! No you don't..... Click your project.... click "Show All Files" .... go into the bin directory.... find the appname.vshost.exe.config file.... OPEN it.... look...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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