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. Help Required in File Operations.

Help Required in File Operations.

Scheduled Pinned Locked Moved C#
csharphelpquestionworkspace
4 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.
  • D Offline
    D Offline
    deepaks3
    wrote on last edited by
    #1

    HI , I am developing a small application in which C# reads a file make changes to it and saves it. The txt files contains dome configuration values say TimeOut=30 ID=abcd Scope=Allowed . . . 1.In my screen i also want to show these values, so what is the method to fetch individual values 2.When i make any change to the value i want it to be saved in that particular line itself. Thanks in Advance.

    Deepak Surana

    C G 2 Replies Last reply
    0
    • D deepaks3

      HI , I am developing a small application in which C# reads a file make changes to it and saves it. The txt files contains dome configuration values say TimeOut=30 ID=abcd Scope=Allowed . . . 1.In my screen i also want to show these values, so what is the method to fetch individual values 2.When i make any change to the value i want it to be saved in that particular line itself. Thanks in Advance.

      Deepak Surana

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

      Why are you using an ini file and not XML ?

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      V 1 Reply Last reply
      0
      • C Christian Graus

        Why are you using an ini file and not XML ?

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #3

        I'm not saying that INI files are the be all and end all of config files, but they are a *lot* easier for novice users to edit, compared to XML files.

        Cheers, Vikram.


        "real dictators don't loose[sic] elections." - Diego Moita.

        1 Reply Last reply
        0
        • D deepaks3

          HI , I am developing a small application in which C# reads a file make changes to it and saves it. The txt files contains dome configuration values say TimeOut=30 ID=abcd Scope=Allowed . . . 1.In my screen i also want to show these values, so what is the method to fetch individual values 2.When i make any change to the value i want it to be saved in that particular line itself. Thanks in Advance.

          Deepak Surana

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          deepaks3 wrote:

          1.In my screen i also want to show these values, so what is the method to fetch individual values

          You can read the values into a dictionary like this:

          Dictionary<string, string> values = new Dictionary<string, string>();
          foreach (string line in File.ReadAllLines(fileName)) {
          string[] data = line.Split('=');
          if (data.Length == 2) values.Add(data[0], data[1]);
          }

          To read a value from the dictionary:

          string id = values["ID"];

          deepaks3 wrote:

          2.When i make any change to the value i want it to be saved in that particular line itself.

          Files are not line based, so you can't change a single line in a file. It's possible to update the file from that line and forward, but it's complicated. Just rewrite the entire file.

          Despite everything, the person most likely to be fooling you next is yourself.

          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