:?:
I am creating a project in VB.NET2005 for reading and writing xml app.config.
but how i want to display the xml data in a message box.
I have used the following code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim astrology_value As String
Dim cricket_value As String
Dim foreigncurrency_value As String
Dim jobs_value As String
Dim app_path As String = System.AppDomain.CurrentDomain.BaseDirectory()

astrology_value = My.Settings.Astrology
cricket_value = My.Settings.Cricket
foreigncurrency_value = My.Settings.Foreigncurrency
jobs_value = My.Settings.Jobs

TextBox1.Text = (astrology_value)
TextBox2.Text = (cricket_value)
TextBox3.Text = (foreigncurrency_value)
TextBox4.Text = (jobs_value)

End Sub
Please help soon
:icon_cry:

Dani AI

Generated

— there are two slightly different goals here and each needs a different approach: showing a few setting values in a MessageBox (what pointed to), versus showing the actual app.config XML content. Concatenating short values into a MessageBox is fine for quick checks, but to display the raw XML you should load the config file, pretty-print it, then present that string.

A simple VB.NET way to load and pretty-print the current configuration file and show it in a MessageBox:

Dim cfgPath As String = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
Dim doc As New System.Xml.XmlDocument()
doc.Load(cfgPath)

Dim sw As New System.IO.StringWriter()
Dim settings As New System.Xml.XmlWriterSettings()
settings.Indent = True

Using xw As System.Xml.XmlWriter = System.Xml.XmlWriter.Create(sw, settings)
    doc.WriteTo(xw)
    xw.Flush()
End Using

MessageBox.Show(sw.ToString(), "Configuration XML")

Notes and troubleshooting:

  • If your values are user-scoped settings they may be saved to a user.config under the user profile, not the exe config. Inspect the file path in cfgPath to be sure you’re viewing the file you expect.
  • MessageBox is poor for long XML (no scrolling or formatting control). For larger XML use a resizable Form with a multiline TextBox (ReadOnly) or export to a .xml file and open in an editor.
  • If a setting shows empty, verify the setting scope (Application vs User) and whether you’re reading the persisted value or defaults.
  • To read specific key/value pairs instead of the whole XML, use ConfigurationManager.AppSettings (add a reference to System.Configuration) or continue using My.Settings for strongly typed settings.

This keeps the raw XML intact and readable while avoiding the typical pitfalls of using MessageBox for large text.

Recommended Answers

All 2 Replies

If you have your info in textboxes then use:
Messagebox.Show(Textbox1.text & VbNewline & Textbox2.text & VbNewline & Textbox3.text & VbNewline & Textbox3.text)

If you have your info in textboxes then use:
Messagebox.Show(Textbox1.text & VbNewline & Textbox2.text & VbNewline & Textbox3.text & VbNewline & Textbox3.text)

Thanx for your reply but I want to display xml file app.config data in message box.......
:S

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.