Skip to content

C# read online text files

mark

Asked Aug 5, 2007, 5:53 PM EDT1 answer
Share
LinkedInX

Im developing a program where I want a textbox to display whats inside a text file located online. So if the text file is located at www.textfile.com/textfile.txt, I want txtDisplayText.Text to display whats in the text file from the file on the website. How would I go about doing this? Thank you!

 

Mark G.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mahesh Chand
    0

    Is this file on your local machine or on the Web Server? If it is on your local machine, first you will have to upload to a folder on the Web server. Make sure this folder has write permissions. Search this site for file upload to learn how to upload a file to a Web server.

    After file is available on the server, you have to pass the physical path of the file on the server. If you do not know the physical path, use MapPath method to get the path.

    After that, you can use TextReader to read the file, loop through all lines and add them to a StringBuilder and set TextBox.Text = StringBuilder.ToString();

    Here is an article on TextReader.

    http://www.c-sharpcorner.com/UploadFile/ggaganesh/TextReaderNWriterGAG12052005235609PM/TextReaderNWriterGAG.aspx

    If you want to display formatted text, you may want to use RichTextBox for that.

    0