Out of Order txt File

Contents are out of order when saving to txt file

Page 1 of 1

2 Replies - 936 Views - Last Post: 28 April 2010 - 08:42 AM Rate Topic: -----

#1 Mallbrig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 16-April 10

Out of Order txt File

Posted 27 April 2010 - 02:03 PM

I have a problem that I cant seem to see around. I am saving items to a text file based off of a users input. If the user clicks the file it saves some standard template information first as a header line. Then based off what they pick I want to add that under the header line in the txt file. Then I want to add the closing footer line to the file. To save myself some headache I am calling to an outside exe file. What is happening is it will do the header and the footer then the contents instead of the header contents and followed by the footer. This is even though the footer comes last in my program. I know I am missing something here probably basic. Thanks in advance!


if (selscale == scale116)//if user picks this option
            {
                //selscalelast = selscale2;
                TextReader tr4 = new StreamReader(@"C:\programname\E16.txt");//I want if this option to copy txt from standard file to new one
                string borderscale = tr4.ReadToEnd();
                tr4.Close();
                tr4.Dispose();
                sw.WriteLine(borderscale);//this is where i write into the new file the header based off this option. This part is in correct place
                sw.Close();//close file
                sw.Dispose();
                System.Diagnostics.Process.Start(@"C:\Program\system\A16.exe");//then i want to add into file things here but it puts it last not 2nd
            }
           //footer line area should be placed third but it is placed second for some reason
            StreamWriter sw2 = new StreamWriter(filename2, true);
            sw2.WriteLine("0");
            sw2.WriteLine("ENDSEC");
            sw2.WriteLine("0");
            sw2.WriteLine("EOF");
            sw2.Close();//close txt file
            sw2.Dispose();



Is This A Good Question/Topic? 0
  • +

Replies To: Out of Order txt File

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Out of Order txt File

Posted 27 April 2010 - 02:17 PM

You have a timing problem. :)

You code starts another process but then continues on without waiting for the new process to finish.

Have a look at Process.HasExited Property

This post has been edited by n8wxs: 27 April 2010 - 02:19 PM

Was This Post Helpful? 1
  • +
  • -

#3 Mallbrig  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 16-April 10

Re: Out of Order txt File

Posted 28 April 2010 - 08:42 AM

View Postn8wxs, on 27 April 2010 - 02:17 PM, said:

You have a timing problem. :)

You code starts another process but then continues on without waiting for the new process to finish.

Have a look at Process.HasExited Property


Thanks so much. I figured It had to something like that I was overlooking something.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1