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. Generate Text File

Generate Text File

Scheduled Pinned Locked Moved C#
help
9 Posts 4 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.
  • T Offline
    T Offline
    tek 2009
    wrote on last edited by
    #1

    I would like to generate the data retrieved from a dictionary in a text file, and I would like your help please, if anyone can help me with ideas or examples. thank you

    OriginalGriffO L 2 Replies Last reply
    0
    • T tek 2009

      I would like to generate the data retrieved from a dictionary in a text file, and I would like your help please, if anyone can help me with ideas or examples. thank you

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Please elaborate on your problem. Am I correct in assuming that you have a Dictionary<type, type> and you want to save it to a text file? If so: 1) Open the file 2) Iterate through your dictionary 3) Write each entry to the file 4) Close the file Which part are you having difficulties with?

      Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      T 1 Reply Last reply
      0
      • T tek 2009

        I would like to generate the data retrieved from a dictionary in a text file, and I would like your help please, if anyone can help me with ideas or examples. thank you

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

        Can you elaborate more on your question, what exactly you are trying to achieve? HTH

        Jinal Desai - LIVE Experience is mother of sage....

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Please elaborate on your problem. Am I correct in assuming that you have a Dictionary<type, type> and you want to save it to a text file? If so: 1) Open the file 2) Iterate through your dictionary 3) Write each entry to the file 4) Close the file Which part are you having difficulties with?

          Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

          T Offline
          T Offline
          tek 2009
          wrote on last edited by
          #4

          I have a dictionary that contains the problems and solutions and I want to write the data into a text file as a table, I'm stuck in the writing of these data in text file

          P OriginalGriffO 2 Replies Last reply
          0
          • T tek 2009

            I have a dictionary that contains the problems and solutions and I want to write the data into a text file as a table, I'm stuck in the writing of these data in text file

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            A simple way to accomplish this is to iterate over the KeyValuePair items and write them out to a Stream. You'll need to delimit the items somehow. I'm not saying this is the best way, but it may achieve exactly what you want.

            "WPF has many lovers. It's a veritable porn star!" - Josh Smith

            As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

            My blog | My articles | MoXAML PowerToys | Onyx

            T 1 Reply Last reply
            0
            • T tek 2009

              I have a dictionary that contains the problems and solutions and I want to write the data into a text file as a table, I'm stuck in the writing of these data in text file

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              tek 2009 wrote:

              want to write the data into a text file as a table

              Well, a text file doesn't hold tables, it only holds flat data, so you will have to decide how to store it so that you can retrieve it later. To save it as flat text is simple:

                      Dictionary<string, string> dict = new Dictionary<string, string>();
                      dict.Add("Hello", "There");
                      dict.Add("Hello again", "There you");
                      dict.Add("Hello again again", "There you are");
                      using (TextWriter tw = File.CreateText(@"C:\\\\temp.txt"))
                          {
                          foreach (KeyValuePair<string, string> kvp in dict)
                              {
                              tw.WriteLine(kvp.Key + ":" + kvp.Value);
                              }
                          tw.Close();
                          }
              

              Anything more complex will need you to think about data storage in a bit more detail!

              Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              T 1 Reply Last reply
              0
              • P Pete OHanlon

                A simple way to accomplish this is to iterate over the KeyValuePair items and write them out to a Stream. You'll need to delimit the items somehow. I'm not saying this is the best way, but it may achieve exactly what you want.

                "WPF has many lovers. It's a veritable porn star!" - Josh Smith

                As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

                My blog | My articles | MoXAML PowerToys | Onyx

                T Offline
                T Offline
                tek 2009
                wrote on last edited by
                #7

                ok, thank you, I'll try and I'll gave the results

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  tek 2009 wrote:

                  want to write the data into a text file as a table

                  Well, a text file doesn't hold tables, it only holds flat data, so you will have to decide how to store it so that you can retrieve it later. To save it as flat text is simple:

                          Dictionary<string, string> dict = new Dictionary<string, string>();
                          dict.Add("Hello", "There");
                          dict.Add("Hello again", "There you");
                          dict.Add("Hello again again", "There you are");
                          using (TextWriter tw = File.CreateText(@"C:\\\\temp.txt"))
                              {
                              foreach (KeyValuePair<string, string> kvp in dict)
                                  {
                                  tw.WriteLine(kvp.Key + ":" + kvp.Value);
                                  }
                              tw.Close();
                              }
                  

                  Anything more complex will need you to think about data storage in a bit more detail!

                  Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

                  T Offline
                  T Offline
                  tek 2009
                  wrote on last edited by
                  #8

                  thank you vey much, it's works , thank you again :)

                  OriginalGriffO 1 Reply Last reply
                  0
                  • T tek 2009

                    thank you vey much, it's works , thank you again :)

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    You're welcome.

                    Did you know: That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    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