14 Mayıs 2010 Cuma

C# da Text Dosyadan Kayıt Silme İşlemi

string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;

private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}

private void button4_Click(object sender, EventArgs e)
{
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);

dosya2 = new FileStream(yol2, FileMode.Create, FileAccess.Write);
StreamWriter yazma;
yazma = new StreamWriter(dosya2);

do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (textBox1.Text != ad)
{
yazma.WriteLine(ad);
yazma.WriteLine(soyad);
yazma.WriteLine(tel);
}
}
while (ad != null);
okuma.Close();
yazma.Close();
File.Delete(yol);
File.Move(yol2, yol);
}

C# da Text Dosyada Kayıt Arama İşlemi

string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;

private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}

private void button3_Click(object sender, EventArgs e)
{
Boolean bul;
bul = false;
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();
if (textBox1.Text == ad)
{
bul = true;
textBox2.Text = soyad;
textBox3.Text = tel;
}
}
while (ad != null);
if (bul == false) MessageBox.Show("Aradığınız Kayıt Bulunamadı");
okuma.Close();
}

C# da Text Dosyadan Okuma İşlemi (Listeleme)

string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;

private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}

private void button2_Click(object sender, EventArgs e)
{
dosya = new FileStream(yol, FileMode.OpenOrCreate, FileAccess.Read);
StreamReader okuma;
okuma = new StreamReader(dosya);
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
do
{
ad = okuma.ReadLine();
soyad = okuma.ReadLine();
tel = okuma.ReadLine();

if (ad != null)
{
listBox1.Items.Add(ad);
listBox2.Items.Add(soyad);
listBox3.Items.Add(tel);
}
}
while (ad != null); //Şart sağlandığı sürece döngü çalışır.
okuma.Close();
}

C# da Text Dosyaya Kayıt İşlemi

string ad, soyad, tel, yol, yol2;
FileStream dosya, dosya2;

private void Form1_Load(object sender, EventArgs e)
{
yol = Application.StartupPath + "\\telefon.txt";
yol2 = Application.StartupPath + "\\gecici.txt";
}
//Kaydet Butonu
private void button1_Click(object sender, EventArgs e)
{
ad = textBox1.Text;
soyad = textBox2.Text;
tel = textBox3.Text;
dosya = new FileStream(yol, FileMode.Append, FileAccess.Write);
StreamWriter yazma;
yazma = new StreamWriter(dosya);
yazma.WriteLine(ad);
yazma.WriteLine(soyad);
yazma.WriteLine(tel);
yazma.Close();
}