0

I want to read the content from the .txt file and display the content at the paragraph tag

on the client side. I absolutely got no idea how can i do that and i do not any function that i use. Please, advice me on this. I looked at this but anything seems to meet my requirements making a paragraph in html contain a text from a file
protected void Button1_Click(object sender, EventArgs e){
        String line;
        String filePath = "C:\\Users\\Administrator\\Test.txt";
        try
        {
            //Pass the file path and file name to the StreamReader constructor
            StreamReader sr = new StreamReader(filePath);

            //Read the first line of text
            line = sr.ReadLine();

            //Continue to read until you reach end of file
            while (line != null)
            {
                //write the lie to console window
                Console.WriteLine(line);
                //Read the next line
                line = sr.ReadLine();
            }

            //close the file
            sr.Close();
            Console.ReadLine();
        }
        catch (Exception e1)
        {
            Console.WriteLine("Exception: " + e1.Message);
        }
        finally
        {
            Console.WriteLine("Executing finally block.");
        }
    }
V. Shikongo
  • 13
  • 1
  • 1
  • 6
  • As you're included ASP.NET tag, you can use `WebMethod` and return contents of text file as a string. Then, in your AJAX call, use `$('#target').text(contents)` to display the content (assumed you have paragraph tag like `

    `).
    – Tetsuya Yamamoto Jan 15 '19 at 06:25

2 Answers2

1

Use <p runat="server" id="para" /> And in your code behind, use this id para and set its text like this

para.InnerHtml = "sample text to be set"
Praneet Nadkar
  • 823
  • 7
  • 16
0

You can make a p tag as runat="server" on your aspx page like this

<p runat="server" id="paragraph"></p>

Then in your code behind (aspx.vb file) after reading all your lines do this:

paragraph.InnerText = "Your variable containing the text";
Nabeel
  • 58
  • 11