Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. application config

application config

Scheduled Pinned Locked Moved Visual Basic
questionhelptutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lisana
    wrote on last edited by
    #1

    I have two application. In the first one, I want to store values to the app.config file from my app textbox, how do I do in the app.config? what should do in the value = "" ? for example: if the textbox1.text = "MyServerName", when the button click, then send the value auto sign to app.config value="MyServerName"... After I install this app. in the target machine, install my second app. I need to read the three value from the app.config. Do I need to create another app.config for the second app or I can read from the same app.config? If I do can read from the same app.config, how should I code it in my second app? Thanks All Your Help! Lisa

    C L 2 Replies Last reply
    0
    • L Lisana

      I have two application. In the first one, I want to store values to the app.config file from my app textbox, how do I do in the app.config? what should do in the value = "" ? for example: if the textbox1.text = "MyServerName", when the button click, then send the value auto sign to app.config value="MyServerName"... After I install this app. in the target machine, install my second app. I need to read the three value from the app.config. Do I need to create another app.config for the second app or I can read from the same app.config? If I do can read from the same app.config, how should I code it in my second app? Thanks All Your Help! Lisa

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      You cannot do this directly. The App.Config file is intended to be read only. i.e. the settings exist already. You will have to read the file in as an XML file, make the modifications and write it out again. There are numerous ways to do this.


      My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      L 1 Reply Last reply
      0
      • C Colin Angus Mackay

        You cannot do this directly. The App.Config file is intended to be read only. i.e. the settings exist already. You will have to read the file in as an XML file, make the modifications and write it out again. There are numerous ways to do this.


        My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        L Offline
        L Offline
        Lisana
        wrote on last edited by
        #3

        how can I read tha app.config from other app. created? it created a menu.exe.config..how can I read it from another application? Lisa

        1 Reply Last reply
        0
        • L Lisana

          I have two application. In the first one, I want to store values to the app.config file from my app textbox, how do I do in the app.config? what should do in the value = "" ? for example: if the textbox1.text = "MyServerName", when the button click, then send the value auto sign to app.config value="MyServerName"... After I install this app. in the target machine, install my second app. I need to read the three value from the app.config. Do I need to create another app.config for the second app or I can read from the same app.config? If I do can read from the same app.config, how should I code it in my second app? Thanks All Your Help! Lisa

          L Offline
          L Offline
          Len Miller
          wrote on last edited by
          #4

          You cannot write a config file during runtim. You will want to serialize an object with your data to an XML file. You can do it like this: 1) Lets say you have an object called CustomSettings that has a bunch of properties that you want to save 2) You can set the appSettingsFullpath to something like: appSettingsFullPath = String.Concat( _ Application.StartupPath, "\custom.settings.xml") 3) Then you can write your CustomSettings object out like this: Dim writer As StreamWriter ' Write (serialize) XML app settings data ' Folder: Try writer = New StreamWriter(appSettingsFullPath) Dim serializer As New XmlSerializer(GetType(CustomSettings)) serializer.Serialize(writer, Me.AppCustomSettings) Catch ex As Exception MessageBox.Show( _ String.Format("Cannot serialize XML settings object.{0}{0}{1}{0}{0}{2}" _ , Microsoft.VisualBasic.ControlChars.CrLf _ , ex.Message, ex.StackTrace) _ ) Finally writer.Close() End Try 4) You can de-serialize (read it) back into your object like this: ' Get (deserialize) XML app settings data ' Folder: Try Dim fileObj As File If Not fileObj.Exists(appSettingsFullPath) Then '** Decide what you need to do here End If fs = New FileStream(appSettingsFullPath, FileMode.Open) Dim csSerializer As New XmlSerializer(GetType(CustomSettings)) '** you can add two event handlers below if you wish ' AddHandler csSerializer.UnknownNode, AddressOf csSerializer_UnknownNode ' AddHandler csSerializer.UnknownAttribute, AddressOf csSerializer_UnknownAttribute Dim cs As SMS.CustomSettings Me.AppCustomSettings = CType(csSerializer.Deserialize(fs), CustomSettings) Catch ex As Exception MessageBox.Show( _ String.Format("Cannot de-serialize XML settings object.{0}{0}{1}{0}{0}{2}" _ , Microsoft.VisualBasic.ControlChars.CrLf _ , ex.Message, ex.StackTrace) _ ) Finally fs.Close() End Try I hope this helps! Thanks, -Len Miller "If I had eight hours to chop down a tree, I'd spend six sharpening my axe." -Abraham Lincoln

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups