Source Code : Form1.cs
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 ReadTextFile
{
public partial class Form1 : Form
{
StreamReader read;
OpenFileDialog Open;
public Form1()
{
InitializeComponent();
Open = new OpenFileDialog();
Open.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Open.Title = "Open your Text file ";
Open.Filter = "|*.txt" ;
}
private void button1_Click(object sender, EventArgs e)
{
if (Open.ShowDialog() == DialogResult.OK)
{
read = new StreamReader(Open.FileName);
richTextBox1.Text = read.ReadToEnd();
groupBox1.Text = Open.FileName;
read.Close();
}
}
}
}
Source Code : Form1.Designer.cs
namespace ReadTextFile
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(111, 217);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(142, 45);
this.button1.TabIndex = 0;
this.button1.Text = "Open Text File";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.richTextBox1);
this.groupBox1.ForeColor = System.Drawing.Color.Red;
this.groupBox1.Location = new System.Drawing.Point(7, 14);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(352, 197);
this.groupBox1.TabIndex = 1;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "My Text";
//
// richTextBox1
//
this.richTextBox1.ForeColor = System.Drawing.Color.Blue;
this.richTextBox1.Location = new System.Drawing.Point(6, 19);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(340, 172);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(364, 274);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = " Read Text File";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
Download :
exe
http://sites.google.com/site/ogremyfiles/ReadTextFile_EXE.rar
Source Code
http://sites.google.com/site/ogremyfiles/ReadTextFile_SourceCode.rar