Verdiğim kodlar senin kodlarından çok uzak değil. zaten sıfırdan ben yazıyor olsam çok farklı yazardım. sana pm ile attığım kodlarda çok fazla yeni bir komut yok.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication8
{
public partial class sil : Form
{
public sil()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
FileStream fs = new FileStream(Application.StartupPath + "\\rehber.txt", FileMode.Open);
StreamReader sr = new StreamReader(fs);
// string dosyaIcerik = sr.ReadToEnd();
string yeniIcerik = string.Empty;
string satir;
do
{
satir = sr.ReadLine();
if (satir != "")
{
String[] satirlar = satir.Split('#');
if (isim.Text.ToUpper() == satirlar[0].ToUpper())
{
fs.Close();
fs.Dispose();
sr.Close();
sr.Dispose();
FileStream fs2 = new FileStream(Application.StartupPath+"\\rehber.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs2);
sw.Write(yeniIcerik);
sw.Close();
sw.Dispose();
fs2.Close();
fs2.Dispose();
MessageBox.Show("Seçtiğiniz isimdeki değerler silindi.", "bilgi");
break;
}
else
{
yeniIcerik += satir + Environment.NewLine ;
}
}
}
while (sr.EndOfStream != true);
sr.Close();
this.Close();
}
catch(Exception ex)
{
MessageBox.Show("DOSYA BULUNAMADI", "HATA", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}