Click here to Skip to main content
15,902,189 members
Home / Discussions / C#
   

C#

 
GeneralInvalidCastException with CAPICOM and webServices Pin
Escroto7-Aug-04 12:50
Escroto7-Aug-04 12:50 
GeneralRe: InvalidCastException with CAPICOM and webServices Pin
Alex Korchemniy7-Aug-04 13:09
Alex Korchemniy7-Aug-04 13:09 
GeneralRe: InvalidCastException with CAPICOM and webServices Pin
beowulfagate7-Aug-04 16:55
beowulfagate7-Aug-04 16:55 
GeneralReplace Task Manager Pin
mrtaikandi7-Aug-04 2:08
professionalmrtaikandi7-Aug-04 2:08 
GeneralRe: Replace Task Manager Pin
Alex Korchemniy7-Aug-04 13:04
Alex Korchemniy7-Aug-04 13:04 
GeneralExecuting an external application Pin
mrtaikandi7-Aug-04 2:00
professionalmrtaikandi7-Aug-04 2:00 
GeneralRe: Executing an external application Pin
Alex Korchemniy7-Aug-04 12:59
Alex Korchemniy7-Aug-04 12:59 
GeneralUrgent - Need help inserting line into text file. Pin
IrishSonic7-Aug-04 1:30
IrishSonic7-Aug-04 1:30 
Hi I have a text file with the following layout:

[PROFILE1]
SYSTEM=home
DEBUG=true

[PROFILE2]
SYSTEM=laptop
DEBUG=true

What I want to do is insert a new line after the FIRST DEBUG LINE in PROFILE1 so the whole of PROFILE2 then moves down a line. My problem is that I keep overwriting the start of PROFILE2 e.g

[PROFILE1]
SYSTEM=home
DEBUG=true
testline
2]
SYSTEM=laptop
DEBUG=true

Can you take a look at my code and see what I am doing wrong!!

if( File.Exists( "d:\\networld.ini" ) )
{
long lFilePos = 0;
string sLine = null;

FileStream fs = new FileStream("d:\\networld.ini",
FileMode.Open, FileAccess.ReadWrite);

// Create a new streams to read and write to the file
StreamReader sr = new StreamReader( fs );
StreamWriter sw = new StreamWriter( fs );

while( sr.Peek() > -1 )
{
sLine = sr.ReadLine();

if( sLine.CompareTo( "[" + "PROFILE1" + "]" ) == 0 )
{
lFilePos = sLine.Length;

while( sr.Peek() > -1 )
{
sLine = sr.ReadLine();

lFilePos += sLine.Length + 2;

if( sLine.CompareTo( "" ) == 0 )
{
fs.Seek( lFilePos,SeekOrigin.Begin );

sw.Write( "testline\r\n" );
sw.Flush();
break;
}
}
}
}

sr.Close();
fs.Close();

MessageBox.Show( "Finished Writing To File." );
}

Thanks a million.

GeneralRe: Urgent - Need help inserting line into text file. Pin
DavidR_r7-Aug-04 2:00
DavidR_r7-Aug-04 2:00 
GeneralRe: Urgent - Need help inserting line into text file. Pin
leppie7-Aug-04 2:32
leppie7-Aug-04 2:32 
GeneralRe: Urgent - Need help inserting line into text file. Pin
IrishSonic7-Aug-04 6:46
IrishSonic7-Aug-04 6:46 
GeneralRe: Urgent - Need help inserting line into text file. Pin
Sue92abc23-Oct-04 8:26
Sue92abc23-Oct-04 8:26 
GeneralSimple Math on a datagrid Pin
christopher_seewald6-Aug-04 23:18
christopher_seewald6-Aug-04 23:18 
GeneralRe: Simple Math on a datagrid Pin
Sukrath Mahajan7-Aug-04 2:03
Sukrath Mahajan7-Aug-04 2:03 
GeneralRe: Simple Math on a datagrid Pin
Robert Rohde8-Aug-04 0:06
Robert Rohde8-Aug-04 0:06 
GeneralA sample cluster program Pin
qi_zhang6-Aug-04 22:29
qi_zhang6-Aug-04 22:29 
GeneralRe: A sample cluster program Pin
Alex Korchemniy7-Aug-04 12:57
Alex Korchemniy7-Aug-04 12:57 
GeneralRe: A sample cluster program Pin
qi_zhang7-Aug-04 16:15
qi_zhang7-Aug-04 16:15 
Generalbase question Pin
Mathew Hall6-Aug-04 22:20
Mathew Hall6-Aug-04 22:20 
GeneralRe: base question Pin
leppie6-Aug-04 23:23
leppie6-Aug-04 23:23 
GeneralRe: base question Pin
Mathew Hall7-Aug-04 1:05
Mathew Hall7-Aug-04 1:05 
GeneralRe: base question Pin
leppie7-Aug-04 1:29
leppie7-Aug-04 1:29 
GeneralGetting notified when a method is called Pin
Robert Rohde6-Aug-04 21:05
Robert Rohde6-Aug-04 21:05 
GeneralRe: Getting notified when a method is called Pin
Angel Reyes6-Aug-04 22:19
Angel Reyes6-Aug-04 22:19 
GeneralRe: Getting notified when a method is called Pin
Robert Rohde6-Aug-04 22:26
Robert Rohde6-Aug-04 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.