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. XML File user output [modified]

XML File user output [modified]

Scheduled Pinned Locked Moved C#
questioncsharpvisual-studioxml
10 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.
  • P Offline
    P Offline
    Pierre besquent
    wrote on last edited by
    #1

    Hi, I generate an Xml File with XmlTextwriter.I saved it in a known path (C:\Documents and Settings\My Documents\Visual Studio 2008myprojects\MyFile.xml). I want now to let the user choose where he wants to save his xml File. How can I import the data from my xml File to copy them in the specified file choosen by the user of my application???? Thank u very much

    modified on Friday, March 11, 2011 5:33 AM

    T M 2 Replies Last reply
    0
    • P Pierre besquent

      Hi, I generate an Xml File with XmlTextwriter.I saved it in a known path (C:\Documents and Settings\My Documents\Visual Studio 2008myprojects\MyFile.xml). I want now to let the user choose where he wants to save his xml File. How can I import the data from my xml File to copy them in the specified file choosen by the user of my application???? Thank u very much

      modified on Friday, March 11, 2011 5:33 AM

      T Offline
      T Offline
      Tarun K S
      wrote on last edited by
      #2

      Good question. Here is how i did. Suppose user selects the path like this :

      Path="C:\MyFile.xml";

      Suppose you have an object of xmlDoc containing the xml. So now we have to create a Filestream for the new path, and then use the StreamWriter class to write the xml to the new path.

      FileStream fs=new FileStream(path,FileMode.Create,FileAccess.ReadWrite);
      StreamWriter sw=new StreamWriter(fs,Text.Encoding.UTF8);
      sw.Write(xmlDoc.OuterXml);
      sw.Close();
      fs.Close();

      Hope it helped! :)

      People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]

      P 1 Reply Last reply
      0
      • T Tarun K S

        Good question. Here is how i did. Suppose user selects the path like this :

        Path="C:\MyFile.xml";

        Suppose you have an object of xmlDoc containing the xml. So now we have to create a Filestream for the new path, and then use the StreamWriter class to write the xml to the new path.

        FileStream fs=new FileStream(path,FileMode.Create,FileAccess.ReadWrite);
        StreamWriter sw=new StreamWriter(fs,Text.Encoding.UTF8);
        sw.Write(xmlDoc.OuterXml);
        sw.Close();
        fs.Close();

        Hope it helped! :)

        People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]

        P Offline
        P Offline
        Pierre besquent
        wrote on last edited by
        #3

        Hi, I don't understand what u mean xmldoc.outerxml??? xmldoc is is my xml document? ty

        T 1 Reply Last reply
        0
        • P Pierre besquent

          Hi, I don't understand what u mean xmldoc.outerxml??? xmldoc is is my xml document? ty

          T Offline
          T Offline
          Tarun K S
          wrote on last edited by
          #4

          xmlDoc is an object of XmlDocument. It will contain your MyFile.xml .

          XmlDocument xmlDoc=new XmlDocument();
          xmlDoc.Load(@"C:\Documents and Settings\My Documents\Visual Studio\MyFile.xml");

          and xmlDoc.OuterXml will give you the whole contents of the xml which will be used to write to the new file.

          People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]

          P 1 Reply Last reply
          0
          • P Pierre besquent

            Hi, I generate an Xml File with XmlTextwriter.I saved it in a known path (C:\Documents and Settings\My Documents\Visual Studio 2008myprojects\MyFile.xml). I want now to let the user choose where he wants to save his xml File. How can I import the data from my xml File to copy them in the specified file choosen by the user of my application???? Thank u very much

            modified on Friday, March 11, 2011 5:33 AM

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            If you are already generating the document in your application then why would you need to import it again. Just save it to where the user wants it when you generate it, rather than saving it to your application directory. If you want to prompt the user for a save location then use the SaveFileDialog[^] Also, if you want to just copy a file from one location to another then use System.IO.File.Copy()

            I may or may not be responsible for my own actions

            1 Reply Last reply
            0
            • T Tarun K S

              xmlDoc is an object of XmlDocument. It will contain your MyFile.xml .

              XmlDocument xmlDoc=new XmlDocument();
              xmlDoc.Load(@"C:\Documents and Settings\My Documents\Visual Studio\MyFile.xml");

              and xmlDoc.OuterXml will give you the whole contents of the xml which will be used to write to the new file.

              People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]

              P Offline
              P Offline
              Pierre besquent
              wrote on last edited by
              #6

              Hi Tarun, Fine my file is well copied but the problem all tags appear in the same ligne. How can i get an organized xml file well organized (tags organized)like this:

              <GrpHdr>
              <MsgId>DOSSIER1</MsgId>
              <CreDtTm>2011-03-07T10:39:29</CreDtTm>
              <BtchBookg>True</BtchBookg>
              <NbOfTxs>2</NbOfTxs>
              <CtrlSum>5534,4</CtrlSum>
              <Grpg>MIXD</Grpg>
              <InitgPty>
              <Nm>Dossier1</Nm>
              </InitgPty>
              </GrpHdr>

              As I conclude, it reads them string. How can I solve that? ty

              T 1 Reply Last reply
              0
              • P Pierre besquent

                Hi Tarun, Fine my file is well copied but the problem all tags appear in the same ligne. How can i get an organized xml file well organized (tags organized)like this:

                <GrpHdr>
                <MsgId>DOSSIER1</MsgId>
                <CreDtTm>2011-03-07T10:39:29</CreDtTm>
                <BtchBookg>True</BtchBookg>
                <NbOfTxs>2</NbOfTxs>
                <CtrlSum>5534,4</CtrlSum>
                <Grpg>MIXD</Grpg>
                <InitgPty>
                <Nm>Dossier1</Nm>
                </InitgPty>
                </GrpHdr>

                As I conclude, it reads them string. How can I solve that? ty

                T Offline
                T Offline
                Tarun K S
                wrote on last edited by
                #7

                I will get back to you on this as soon as i find the solution.

                People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]

                P 2 Replies Last reply
                0
                • T Tarun K S

                  I will get back to you on this as soon as i find the solution.

                  People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]

                  P Offline
                  P Offline
                  Pierre besquent
                  wrote on last edited by
                  #8

                  Hi, even if I use Text.Encoding.UTF8 the file still not organized like an xml File format. Thank u for u help on this (still waiting for u help :) )

                  1 Reply Last reply
                  0
                  • T Tarun K S

                    I will get back to you on this as soon as i find the solution.

                    People with high attitude deserve the standing ovation of our highest finger! My Technical Blog![^]

                    P Offline
                    P Offline
                    Pierre besquent
                    wrote on last edited by
                    #9

                    hello Turan, I found a solution. i just add the text.encoding UTF-8 to my code:

                    this.Response.ContentEncoding = Encoding.GetEncoding ("UTF-8");

                    I open my file with an Xml editor all works fine and my File is well structred. Thank u a lot for u help and I am now sssssssssssssssso happy. :laugh:

                    T 1 Reply Last reply
                    0
                    • P Pierre besquent

                      hello Turan, I found a solution. i just add the text.encoding UTF-8 to my code:

                      this.Response.ContentEncoding = Encoding.GetEncoding ("UTF-8");

                      I open my file with an Xml editor all works fine and my File is well structred. Thank u a lot for u help and I am now sssssssssssssssso happy. :laugh:

                      T Offline
                      T Offline
                      Tarun K S
                      wrote on last edited by
                      #10

                      Awesome! :-D

                      People with high attitude deserve the standing ovation of our highest finger! My Blog![^]

                      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