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. Reading a txt file to set properties ?

Reading a txt file to set properties ?

Scheduled Pinned Locked Moved C#
tutorialquestion
5 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:

    L M T 4 Replies Last reply
    0
    • A Anonymous

      I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      Anonymous wrote: private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; }

      private Hashtable ReadFile(string filename)
      {
      string s;
      Regex re = new Regex(@"^\s*(?<name>\w+)\s*=\s*(?<value>.+?)\s*$",
      RegexOptions.ExplicitCapture);
      Hashtable nv = new Hashtable();
      StreamReader sr = File.OpenText(filename);
      while ((s = sr.ReadLine()) != null)
      {
      Match m = re.Match(s);
      if (m.Success)
      {
      nv.Add(m.Groups["name"].Value, m.Groups["value"].Value);
      }
      }
      sr.Close();
      return nv;
      }

      top secret xacc-ide 0.0.1

      1 Reply Last reply
      0
      • A Anonymous

        I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:

        M Offline
        M Offline
        MilesAhead
        wrote on last edited by
        #3

        Sounds like what I use .ini files for. I think there's a C# article on Code Project that encapsulates WritePrivateProfileString and ReadPrivateProfileString. Or you could DLLImport them and roll your own. Delphi has a pretty nice TIniFile class so what I did was write a dual-interface COM wrapper for it so I could use it with anything that can use COM. I haven't tried it with C# yet though. It worked fine with VB 6 and VC++ 6.

        1 Reply Last reply
        0
        • A Anonymous

          I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:

          T Offline
          T Offline
          triso
          wrote on last edited by
          #4

          Thanks for the replies, any other ways of doing this ?

          1 Reply Last reply
          0
          • A Anonymous

            I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:

            T Offline
            T Offline
            triso
            wrote on last edited by
            #5

            It is kind of like any INI file, but you instead of initializing the component on startup, you are just setting its propeties. I realize this is not the best way to do this, however this is an exercise I must complete. Thanks for the replies, any other ways of doing this ?

            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