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. Problem While Writing To A Text File

Problem While Writing To A Text File

Scheduled Pinned Locked Moved C#
helphtml
4 Posts 2 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.
  • R Offline
    R Offline
    rowdykuttan
    wrote on last edited by
    #1

    Hi all, Am replacing a particular string with another string of a text file dynamically. but while doing this am putting them to a richtextbox also. the contents of this text file contains lot of HTML tags. right now am facing alignment problems. here is the code i have for replacing can some one help me with better solutions than mine <------------------CODE---------------------> public void ConvertFile(string Pathstring) { bool change = false; StreamReader re = File.OpenText(Pathstring); string test = ""; string input = null; string fileName = Pathstring; while ((input = re.ReadLine()) != null) { if (input.Contains("XXX-XX")) { change = true; } if (change == true) { if (input.Contains(".jpg")) { if (test.Contains("XXX-XX")) { test = test.Replace("XXX-XX", GetFilename((input))); } } } test += input+"\r\n"; } re.Close(); richTextBox1.Text = test; } <------------------END OF CODE--------------------->

    C 1 Reply Last reply
    0
    • R rowdykuttan

      Hi all, Am replacing a particular string with another string of a text file dynamically. but while doing this am putting them to a richtextbox also. the contents of this text file contains lot of HTML tags. right now am facing alignment problems. here is the code i have for replacing can some one help me with better solutions than mine <------------------CODE---------------------> public void ConvertFile(string Pathstring) { bool change = false; StreamReader re = File.OpenText(Pathstring); string test = ""; string input = null; string fileName = Pathstring; while ((input = re.ReadLine()) != null) { if (input.Contains("XXX-XX")) { change = true; } if (change == true) { if (input.Contains(".jpg")) { if (test.Contains("XXX-XX")) { test = test.Replace("XXX-XX", GetFilename((input))); } } } test += input+"\r\n"; } re.Close(); richTextBox1.Text = test; } <------------------END OF CODE--------------------->

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

      I see you've taken none of the advice you were given the other day ?

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      R 1 Reply Last reply
      0
      • C Christian Graus

        I see you've taken none of the advice you were given the other day ?

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        R Offline
        R Offline
        rowdykuttan
        wrote on last edited by
        #3

        Yes if i give File.WriteAll, i tried but it was not working, cause its taking last file name and writing it on places of XXX-XX.

        C 1 Reply Last reply
        0
        • R rowdykuttan

          Yes if i give File.WriteAll, i tried but it was not working, cause its taking last file name and writing it on places of XXX-XX.

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

          I don't follow you ? if you create a string [] by calling File.ReadAllLines, you can iterate over the lines and call your method to get the filename, and then call File.WriteAllLines. Putting it in a richtextbox is superfluous, unless you want the user to hand edit the file. Even then, a text control makes more sense, b/c you don't have rich text to start with, do you ?

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

          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