Hi all,

Iam developing one windows application in that i have to open one text file and read it from http link on website like: "http:\\website\dir\sample.txt" iam using c# as language.How to do this.

Recommended Answers

All 4 Replies

google is your friend.


Check httpwebresponse and httpwebrequest

It's very simple you can do this in one single line
First, include the System.IO;

if you have permission to read from files

string Contents = new StreamReader(path).ReadToEnd();

Thanks for the replies.

I got the solution this way...

url = "http:\\website\dir\sample.txt";
                      
            Uri uri = new Uri(url);

            //Create the request object

            WebRequest req = WebRequest.Create(uri);
            WebResponse resp = req.GetResponse();
            Stream stream = resp.GetResponseStream();
            StreamReader sr = new StreamReader(stream);

            string s = sr.ReadToEnd();

Please mark the thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.