473,396 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

code in c# to enter some text from a textfile into textbox

5
hi......

pls tell the code in C#.net to display the texts from a textfile to the textbox.
pls explain how to do this....
Sep 14 '07 #1
6 1616
ammoos
100 100+
You can Read from a text file by using the System.IO.StreamReader object..


Check this Link
read a text file by using System.IO
Sep 14 '07 #2
svsugu
5
thank you.....
but one more doubt.. how can we display those texts in textbox?
Sep 14 '07 #3
svsugu
5
hi....
using openFileDialog i opened the required text file... but i want show that file contents into the textbox. now its showing the path of the file in that textbox......
Sep 14 '07 #4
ammoos
100 100+
Hope you Read the document

StreamReader objReader = new StreamReader("c:\\test.txt");
string sLine="";
while (sLine != null)
{
sLine = objReader.ReadLine();
if (sLine != null)
TextBox1.Text=TextBox1.Text + sLine;
}
objReader.Close();
Sep 14 '07 #5
debasisdas
8,127 Expert 4TB
try to read from the file and display the content to the textbox not the filename.
Sep 14 '07 #6
shweta123
692 Expert 512MB
Hi,

Try this code for reading from the file

Public Function GetFileContents(ByVal FullPath As String, _
Optional ByRef ErrInfo As String = "") As String
Dim strContents As String
Dim objReader As StreamReader
Try
objReader = New StreamReader(FullPath)
strContents = objReader.ReadToEnd()
objReader.Close()
Return strContents
Catch Ex As Exception
ErrInfo = Ex.Message
End Try
End Function

TextBox1.Text = GetFileContents(yourfilepath)
Sep 14 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Susan | last post by:
AccessXP When I use the wizard to create a form, all the textboxes are created with the Enter Key Behaviour of "New Line In Field". When I create the form manually the Enter Key Behaviour is...
10
by: mg | last post by:
I want to enter characters in a TextBox in a WebForm, press a Button in the WebForm, and read the characters that were typed into the TextBox from within the Button_Click event handler. The main...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
17
by: J.S. | last post by:
I have a text file with parameters like the following embedded in the text: @@TextBox1@@, @@TextBox2@@, etc. I know how to read this text file. However, I am trying to figure out how to...
0
by: karen987 | last post by:
Please could someone help me with this code? The problem appears to be a simple one, but i'm not html or ASP literate and need to modify the below code to add 2 things. First a bit about the...
1
by: Radu | last post by:
Hi. I am trying to localize a page AND simulate the AJAX watermarks in it, i.e. the textbox contains the text "Enter your name", or "Entrez votre nom", for instance, then on click, delete this...
6
by: Mark B | last post by:
I have a function that looks up a SQL table to see if a search term matches. It works fine but so far there are two things yet to work: 1) After entering a search term and pressing Enter, nothing...
3
by: SteveB | last post by:
I have posted this question in the Visual Basic 2005 and Visual Basic .Net 2005 discussion groups, also. Hi. I am developing an application/web page with VB.Net that will populate a SQL...
1
by: vinya | last post by:
<html> <head> <script type="text/javascript"> var element; function test(){ abc = document.getElementById('promptbox').value; document.forms.elements.value = abc; ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.