p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 1.0 and 1.1 Basics (http://p2p.wrox.com/forumdisplay.php?f=60)

 senthilreddy May 21st, 2007 10:00 PM

HI Guyz,

I'm a newbie in asp.net. What i would like to do is read a text file , take certain values and post them back in a page.

For example let say a a.txt file which contains :

name :

senthil

age :

20

jjjjjjj

llllllll

name :

jenna

age :

25

designation :

teacher

llllllllllll

-----------------------------------------------------------------------

i would like to take only the values next to line with name and age only :::: name (jenna,senthil) age:(20,25)

and post them back in a new page.

i could read the whole file and post everything.:

<%@ Import Namespace="System.IO" %>

<SCRIPT Runat="Server">

Sub Read_File_Fields (Src As Object, Args As EventArgs)

FileReader = File.OpenText("C:\Documents and Settings\user1\My Documents\Works Senthil\Celcom Billing\17.Celcom - Billing\02.Celcom-Dell\TH.dat")

Dim LineIn As String
Dim FieldArray() As String
Dim Field As String

If Not LineIn = Nothing Then
FieldArray = Split(LineIn, ",")

FileContents.Text &= "<table border=""1"">"
FileContents.Text &= "<tr style=""background-color:#F0F0F0"">"
For Each Field in FieldArray
FileContents.Text &= "<th>" & Field & "</th>"
Next
FileContents.Text &= "</tr>"

'-- Display table rows
While LineIn <> Nothing
FieldArray = Split(LineIn, ",")

'-- Display a table row
FileContents.Text &= "<tr>"
For Each Field in FieldArray
FileContents.Text &= "<td>" & Field & "</td>"
Next
FileContents.Text &= "</tr>"

End While

FileContents.Text &= "</table>"
End If

End Sub

</SCRIPT>

<form id="Form1" Runat="Server">

<p><asp:Label id="FileContents" EnableViewState="False" Runat="Server"/></p>

</form>
----------

How could i pick only a few values such as the name and age. The values for name is on the next line. Help me out if there is a way. I'm using vwd with sql express.the place i'm stuck is how to search for the line says (age/name) and find for the next line. i could noy picturize how the codes could look like. thank you for ya help.

 pons_saravanan December 19th, 2010 10:56 PM

It is a very old question, but if anyone struggles in the same way you may use the following

You can use the filesystem for Vb.Net Read Text File easily pass the string into a variable.

split the string using name or read until you find 'name' in the string. then for each stop read the other attributes(age, etc...) then use another string to form the display string as you did in your code.

 All times are GMT -4. The time now is 04:35 PM.