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
  1. Home
  2. General Programming
  3. C#
  4. how to write the values in textbox to xml format..

how to write the values in textbox to xml format..

Scheduled Pinned Locked Moved C#
csharpdatabaseasp-netxmlhelp
9 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.
  • S Offline
    S Offline
    samsonx
    wrote on last edited by
    #1

    Hi, Am working in Asp.net using C#.I have 4 textboxes and 1 button in my application.After the user enters values in 4 textboxes he will click the button.On button click the values in textbox should be written in XML format....Usually to insert values in database we will use INSERT query..But instead of saving in Database i should write the values in textbox directly to XML. S it possible to write the values in Textbox directly to xml??? Can u help me in doing this....Thanx in advance..

    Regards, Samson

    L 1 Reply Last reply
    0
    • S samsonx

      Hi, Am working in Asp.net using C#.I have 4 textboxes and 1 button in my application.After the user enters values in 4 textboxes he will click the button.On button click the values in textbox should be written in XML format....Usually to insert values in database we will use INSERT query..But instead of saving in Database i should write the values in textbox directly to XML. S it possible to write the values in Textbox directly to xml??? Can u help me in doing this....Thanx in advance..

      Regards, Samson

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Yes, that is possible. Try this little horrorcode;

      string asXML = @"<codinghorrorxml>" + Environment.NewLine;
      asXML += @"<textbox1>" + textBox1.Text + @"</textbox1>" + Environment.NewLine;
      asXML += @"<textbox2>" + textBox2.Text + @"</textbox2>" + Environment.NewLine;
      asXML += @"<textbox3>" + textBox3.Text + @"</textbox3>" + Environment.NewLine;
      asXML += @"</codinghorrorxml>";

      You'll also need to write this string to disk, I presume. There's a StreamWriter somewhere in System.IO.

      I are troll :)

      S 1 Reply Last reply
      0
      • L Lost User

        Yes, that is possible. Try this little horrorcode;

        string asXML = @"<codinghorrorxml>" + Environment.NewLine;
        asXML += @"<textbox1>" + textBox1.Text + @"</textbox1>" + Environment.NewLine;
        asXML += @"<textbox2>" + textBox2.Text + @"</textbox2>" + Environment.NewLine;
        asXML += @"<textbox3>" + textBox3.Text + @"</textbox3>" + Environment.NewLine;
        asXML += @"</codinghorrorxml>";

        You'll also need to write this string to disk, I presume. There's a StreamWriter somewhere in System.IO.

        I are troll :)

        S Offline
        S Offline
        samsonx
        wrote on last edited by
        #3

        hi, I don know how to use streamwriter and save the xml... Please give me some idea over there... Thanks in advance

        Regards, Samson

        L 1 Reply Last reply
        0
        • S samsonx

          hi, I don know how to use streamwriter and save the xml... Please give me some idea over there... Thanks in advance

          Regards, Samson

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          There's an example here. Good luck :)

          I are troll :)

          S 1 Reply Last reply
          0
          • L Lost User

            There's an example here. Good luck :)

            I are troll :)

            S Offline
            S Offline
            samsonx
            wrote on last edited by
            #5

            Hi, I created the code and run it but it's not creating a new xml file... I pasted my code her... please let me know what to correct it string asXML = @"" + Environment.NewLine; asXML += @"" + txtid.Text + @"" + Environment.NewLine; asXML += @"" + txtname.Text + @"" + Environment.NewLine; asXML += @"" + txtage.Text + @"" + Environment.NewLine; asXML += @""; FileStream test= new FileStream("test.xml", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(test); sw.Write("Hello file system world!"); sw.Close(); test.Close(); It's not creating the test.xml file... Please correct it... Thanks in advance

            Regards, Samson

            S C 2 Replies Last reply
            0
            • S samsonx

              Hi, I created the code and run it but it's not creating a new xml file... I pasted my code her... please let me know what to correct it string asXML = @"" + Environment.NewLine; asXML += @"" + txtid.Text + @"" + Environment.NewLine; asXML += @"" + txtname.Text + @"" + Environment.NewLine; asXML += @"" + txtage.Text + @"" + Environment.NewLine; asXML += @""; FileStream test= new FileStream("test.xml", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(test); sw.Write("Hello file system world!"); sw.Close(); test.Close(); It's not creating the test.xml file... Please correct it... Thanks in advance

              Regards, Samson

              S Offline
              S Offline
              samsonx
              wrote on last edited by
              #6

              Here i had change the code as sw.write(asXML); i got the xml file,but it's not writing the value from textbox. I'm Getting the folloeing error. XML document must have a top level element. Error processing resource 'file:///C:/Documents and Settings/sbritto/Desktop/test.xml Please correct it... Thanks in advance

              With Regards, Samson

              C 1 Reply Last reply
              0
              • S samsonx

                Hi, I created the code and run it but it's not creating a new xml file... I pasted my code her... please let me know what to correct it string asXML = @"" + Environment.NewLine; asXML += @"" + txtid.Text + @"" + Environment.NewLine; asXML += @"" + txtname.Text + @"" + Environment.NewLine; asXML += @"" + txtage.Text + @"" + Environment.NewLine; asXML += @""; FileStream test= new FileStream("test.xml", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(test); sw.Write("Hello file system world!"); sw.Close(); test.Close(); It's not creating the test.xml file... Please correct it... Thanks in advance

                Regards, Samson

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                samsonx wrote:

                Please correct it...

                Well, I'd recommend you do some reading on XML, and possibly C#. You either are hoping for some sort of magic to happen that has nothing to do with any code that you've written, or you plain have no idea. You've not written any nodes here, this would only work if you magically happened to type the right values into your textboxes to create XML. Either way, as the original guy said, this is horrible code. XmlTextWriter is the class you should be using. I've confirmed that there's tons of info and examples on the web, easily found with your search engine of choice.

                Christian Graus Driven to the arms of OSX by Vista.

                L 1 Reply Last reply
                0
                • S samsonx

                  Here i had change the code as sw.write(asXML); i got the xml file,but it's not writing the value from textbox. I'm Getting the folloeing error. XML document must have a top level element. Error processing resource 'file:///C:/Documents and Settings/sbritto/Desktop/test.xml Please correct it... Thanks in advance

                  With Regards, Samson

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  you're not writing XML. Stop flailing about in the dark, abandon the path of ignorance, and actually do some work to establish that the code you enter stands some semblance of a chance of working.

                  Christian Graus Driven to the arms of OSX by Vista.

                  1 Reply Last reply
                  0
                  • C Christian Graus

                    samsonx wrote:

                    Please correct it...

                    Well, I'd recommend you do some reading on XML, and possibly C#. You either are hoping for some sort of magic to happen that has nothing to do with any code that you've written, or you plain have no idea. You've not written any nodes here, this would only work if you magically happened to type the right values into your textboxes to create XML. Either way, as the original guy said, this is horrible code. XmlTextWriter is the class you should be using. I've confirmed that there's tons of info and examples on the web, easily found with your search engine of choice.

                    Christian Graus Driven to the arms of OSX by Vista.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    Christian Graus wrote:

                    Either way, as the original guy said, this is horrible code.

                    I'm having fun here :cool:

                    I are troll :)

                    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