Click here to Skip to main content
15,888,984 members
Home / Discussions / C#
   

C#

 
GeneralRe: Hiding main form upon load Pin
Justin Perez11-Sep-07 3:21
Justin Perez11-Sep-07 3:21 
GeneralRe: Hiding main form upon load Pin
Giorgi Dalakishvili11-Sep-07 3:26
mentorGiorgi Dalakishvili11-Sep-07 3:26 
JokeRe: internet speed Pin
Ed.Poore11-Sep-07 2:53
Ed.Poore11-Sep-07 2:53 
QuestionActiveX Exception Pin
DeepOceans11-Sep-07 2:12
DeepOceans11-Sep-07 2:12 
AnswerRe: ActiveX Exception Pin
Justin Perez11-Sep-07 2:27
Justin Perez11-Sep-07 2:27 
GeneralRe: ActiveX Exception Pin
DeepOceans11-Sep-07 21:43
DeepOceans11-Sep-07 21:43 
Questionhow do i delete lines from .txt file? "Urgent!" Pin
andredani11-Sep-07 2:04
andredani11-Sep-07 2:04 
AnswerRe: how do i delete lines from .txt file? "Urgent!" Pin
Christian Wulff11-Sep-07 2:21
Christian Wulff11-Sep-07 2:21 
Hi,

you can do that if you create a temporary file, copy only the lines which should not be deleted to that temp file and later overwrite the original file with the temp file.

E.g:

string tempFilename = System.IO.Path.GetTempFileName();
using (StreamReader sr = new StreamReader(path1 + ""))
using (StreamWriter sw = new StreamWriter(tempFilename))
{
    while (sr.Peek() > 0)
    {
        line = sr.ReadLine();
        if (line == "#")
        {
            name = sr.ReadLine();
            nameAndJob = string.Concat(name);
            Job = string.Concat(name);
            if (list.ContainsKey(nameAndJob))
            {
                item1 = list[nameAndJob];
                item1 = list[Job];
                item1.SubItems[1].Text = sr.ReadLine();
                item1.SubItems[3].Text = sr.ReadLine();
                item1.SubItems[5].Text = sr.ReadLine();
                /////////// Can i delete this lines in .txt file
            }
            else
            {
                // Write the "#" line
                sw.WriteLine("#");
                // Write the name which was read above
                sw.WriteLine(name);
                // The next three lines will be written in the else block below
            }
        }
        else
        {
            sw.WriteLine(line);
        }
    }
    sw.Flush();
}
System.IO.File.Delete(path1 + "/personalpr.txt");
System.IO.File.Move(tempFilename, path1 + "/personalpr.txt");

I didn't test the code, but I think you want something like that.
GeneralRe: how do i delete lines from .txt file? "Urgent!" Pin
andredani11-Sep-07 3:24
andredani11-Sep-07 3:24 
GeneralRe: how do i delete lines from .txt file? "Urgent!" Pin
Christian Wulff11-Sep-07 6:37
Christian Wulff11-Sep-07 6:37 
GeneralRe: how do i delete lines from .txt file? "Urgent!" Pin
andredani11-Sep-07 9:03
andredani11-Sep-07 9:03 
GeneralRe: how do i delete lines from .txt file? "Urgent!" Pin
Christian Wulff11-Sep-07 11:18
Christian Wulff11-Sep-07 11:18 
GeneralRe: how do i delete lines from .txt file? "Urgent!" [modified] Pin
andredani11-Sep-07 12:15
andredani11-Sep-07 12:15 
AnswerRe: how do i delete lines from .txt file? "Urgent!" Pin
pmarfleet11-Sep-07 2:28
pmarfleet11-Sep-07 2:28 
QuestionSelecting unique nodes from an XML file Pin
Rocky#11-Sep-07 1:43
Rocky#11-Sep-07 1:43 
AnswerRe: Selecting unique nodes from an XML file Pin
Ed.Poore11-Sep-07 2:55
Ed.Poore11-Sep-07 2:55 
GeneralRe: Selecting unique nodes from an XML file Pin
Rocky#11-Sep-07 3:01
Rocky#11-Sep-07 3:01 
GeneralRe: Selecting unique nodes from an XML file Pin
Ed.Poore11-Sep-07 3:45
Ed.Poore11-Sep-07 3:45 
GeneralRe: Selecting unique nodes from an XML file Pin
Rocky#11-Sep-07 20:38
Rocky#11-Sep-07 20:38 
GeneralRe: Selecting unique nodes from an XML file Pin
Ed.Poore11-Sep-07 22:40
Ed.Poore11-Sep-07 22:40 
AnswerRe: Selecting unique nodes from an XML file Pin
Rocky#12-Sep-07 0:42
Rocky#12-Sep-07 0:42 
QuestionMFC-like programming Pin
perrin486911-Sep-07 1:39
perrin486911-Sep-07 1:39 
AnswerRe: MFC-like programming Pin
originSH11-Sep-07 2:00
originSH11-Sep-07 2:00 
GeneralRe: MFC-like programming Pin
perrin486911-Sep-07 2:24
perrin486911-Sep-07 2:24 
AnswerRe: datagridview update database error Pin
Rocky#11-Sep-07 1:41
Rocky#11-Sep-07 1:41 

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.