Click here to Skip to main content
15,913,090 members
Home / Discussions / C#
   

C#

 
AnswerRe: Garbage collector Message; how to solve it? Pin
Guffa16-Nov-07 23:35
Guffa16-Nov-07 23:35 
Question(WPF)Random problem? [solved] Pin
wolfshad316-Nov-07 20:50
wolfshad316-Nov-07 20:50 
QuestionAuto Calculate An Age Without Postback a Page Pin
Gandalf_TheWhite16-Nov-07 20:19
professionalGandalf_TheWhite16-Nov-07 20:19 
AnswerRe: Auto Calculate An Age Without Postback a Page Pin
Mircea Puiu16-Nov-07 20:43
Mircea Puiu16-Nov-07 20:43 
GeneralRe: Auto Calculate An Age Without Postback a Page Pin
Gandalf_TheWhite16-Nov-07 21:25
professionalGandalf_TheWhite16-Nov-07 21:25 
GeneralRe: Auto Calculate An Age Without Postback a Page Pin
Brady Kelly16-Nov-07 21:58
Brady Kelly16-Nov-07 21:58 
AnswerRe: Auto Calculate An Age Without Postback a Page Pin
Christian Graus16-Nov-07 22:01
protectorChristian Graus16-Nov-07 22:01 
Questiondisplay in a textbox contents from a .txt file [modified] Pin
new2pgrmg16-Nov-07 20:18
new2pgrmg16-Nov-07 20:18 
Hi,

How to read contents of a file(.txt) and display it in a textbox in C# windows form

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 TEST
{
public partial class Form1 : Form
{
//string connection;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog objDialog = new OpenFileDialog();
objDialog.Title = "Open .cs File";
objDialog.Filter = "C Sharp Files (*.cs)|*.cs|Text Files (*.txt)|*.txt";
objDialog.InitialDirectory = @"D:\back up d triassic\users\k\Training\ConsoleApplication1";
if (objDialog.ShowDialog() == DialogResult.OK)
{

MessageBox.Show(objDialog.FileName.ToString());

}
listBox1.Items.Add(@"D:\back up d triassic\users\k\Training\ConsoleApplication1");
read();
Open();

}
public static void Open()
{
FileStream file = new FileStream(@"D:\back up d triassic\users\k\Training\ConsoleApplication1\ConsoleApplication1\Program.cs", FileMode.Open, FileAccess.Read);

// Create a new stream to read from a file
StreamReader sr = new StreamReader(file);

// Read contents of file into a string
string s = sr.ReadToEnd();

// Close StreamReader
sr.Close();
}

public static void read()
{
FileStream file = new FileStream(@"D:\back up d triassic\users\k\Training\ConsoleApplication1\ConsoleApplication1\Program.cs", FileMode.Open, FileAccess.Read);

// Create a new stream to read from a file
StreamReader sr = new StreamReader(file);

// Read contents of file into a string
string s = sr.ReadToEnd();

// Close StreamReader
sr.Close();

// Close file
file.Close();
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}






Am stuck here.
Can anybody help me?

j


-- modified at 7:20 Saturday 17th November, 2007
AnswerRe: display in a textbox contents from a .txt file Pin
Abhijit Jana16-Nov-07 20:31
professionalAbhijit Jana16-Nov-07 20:31 
AnswerRe: display in a textbox contents from a .txt file Pin
Abhijit Jana16-Nov-07 20:32
professionalAbhijit Jana16-Nov-07 20:32 
AnswerRe: display in a textbox contents from a .txt file Pin
Mircea Puiu16-Nov-07 20:51
Mircea Puiu16-Nov-07 20:51 
AnswerRe: display in a textbox contents from a .txt file Pin
Christian Graus16-Nov-07 22:52
protectorChristian Graus16-Nov-07 22:52 
QuestionThis is weird!!! Pin
kingletas16-Nov-07 18:56
kingletas16-Nov-07 18:56 
AnswerRe: This is weird!!! Pin
mav.northwind16-Nov-07 21:33
mav.northwind16-Nov-07 21:33 
Questionreg: Go to line number in text file Pin
Satish - Developer16-Nov-07 18:09
Satish - Developer16-Nov-07 18:09 
AnswerRe: reg: Go to line number in text file Pin
Christian Graus16-Nov-07 18:41
protectorChristian Graus16-Nov-07 18:41 
GeneralRe: reg: Go to line number in text file Pin
Satish - Developer16-Nov-07 18:51
Satish - Developer16-Nov-07 18:51 
GeneralRe: reg: Go to line number in text file Pin
Christian Graus16-Nov-07 22:54
protectorChristian Graus16-Nov-07 22:54 
AnswerRe: reg: Go to line number in text file Pin
Sun Rays16-Nov-07 18:45
Sun Rays16-Nov-07 18:45 
GeneralRe: reg: Go to line number in text file Pin
Satish - Developer16-Nov-07 18:54
Satish - Developer16-Nov-07 18:54 
AnswerRe: reg: Go to line number in text file Pin
Guffa16-Nov-07 23:39
Guffa16-Nov-07 23:39 
QuestionValues Form Radio Button In UserContol Pin
MuraleeKrishnan16-Nov-07 17:37
MuraleeKrishnan16-Nov-07 17:37 
AnswerRe: Values Form Radio Button In UserContol Pin
SABhatti16-Nov-07 17:47
SABhatti16-Nov-07 17:47 
QuestionHow to copy data table to arraylist ...? Pin
Pankaj - Joshi16-Nov-07 16:12
Pankaj - Joshi16-Nov-07 16:12 
AnswerRe: How to copy data table to arraylist ...? Pin
SABhatti16-Nov-07 17:54
SABhatti16-Nov-07 17:54 

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.