Search This Blog

2010/01/17

Flat File Handling in C#:

Creating New Text File If It Does’nt Exist ,Else Open That Existing File & Writing Text Data To It.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Flat_File_Handling
{
public partial class Form1 : Form
{
FileStream Fstream;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string strPath = textBox1.Text;
try
{
Fstream = new FileStream(strPath, FileMode.OpenOrCreate );
}
catch(IOException IOExp)
{
MessageBox.Show(IOExp.Message);
}

}

private void button2_Click(object sender, EventArgs e)
{
StreamWriter swriter = new StreamWriter(Fstream);
swriter.Write(textBox2.Text);
swriter.Close();
Fstream.Close();
}
}
}

No comments:

Post a Comment