Sainath Reddy

Sainath Reddy

  • NA
  • 101
  • 1.4k

Reading a text file from local and paste in a label

Aug 3 2019 1:29 AM
Hi friend i have one requiremnt can you help me
 
we need to pick up a txt file from our local system ssuppose c:\textfile,.txt
 
in txt file if we have 4 lines
 
text 1
text 2
text 3
text4
 
i need to need pick only the 2and 3 lines and need to paste it in the web application specific textboxs
 
text2 --textbox 1
text3 --textbox 2
 
sample code i have tried in console
 
can any one help me through web applicaton the same thing
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Text;  
  4. using System.IO;  
  5. namespace textfilereading {  
  6.  class Program {  
  7.   static void Main(string[] args) {  
  8.    //Load our text file  
  9.    TextReader tr = new StreamReader(@ "G:\tetfile.txt");  
  10.    //How many lines should be loaded?  
  11.    int NumberOfLines = 15;  
  12.    //Make our array for each line  
  13.    string[] ListLines = new string[NumberOfLines];  
  14.    //Read the number of lines and put them in the array  
  15.    for (int i = 1; i < NumberOfLines; i++) {  
  16.     ListLines[i] = tr.ReadLine();  
  17.    }  
  18.    //This will write the 5th line into the console  
  19.    Console.WriteLine(ListLines[5]);  
  20.    //This will write the 1st line into the console  
  21.    Console.WriteLine(ListLines[1]);  
  22.    Console.ReadLine();  
  23.    // close the stream  
  24.    tr.Close();  
  25.   }  
  26.  }  
  27. }

Answers (1)