943,580 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 9176
  • C# RSS
Nov 12th, 2008
0

how to open and text file on web from windows application

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mrkcse is offline Offline
9 posts
since Apr 2008
Nov 12th, 2008
0

Re: how to open and text file on web from windows application

google is your friend.


Check httpwebresponse and httpwebrequest
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Nov 12th, 2008
0

Re: how to open and text file on web from windows application

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();
Reputation Points: 11
Solved Threads: 16
Junior Poster
Jugortha is offline Offline
172 posts
since Oct 2007
Nov 13th, 2008
0

Re: how to open and text file on web from windows application

Thanks for the replies.

I got the solution this way...

C# Syntax (Toggle Plain Text)
  1.  
  2. url = "http:\\website\dir\sample.txt";
  3.  
  4. Uri uri = new Uri(url);
  5.  
  6. //Create the request object
  7.  
  8. WebRequest req = WebRequest.Create(uri);
  9. WebResponse resp = req.GetResponse();
  10. Stream stream = resp.GetResponseStream();
  11. StreamReader sr = new StreamReader(stream);
  12.  
  13. string s = sr.ReadToEnd();
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mrkcse is offline Offline
9 posts
since Apr 2008
Nov 13th, 2008
0

Re: how to open and text file on web from windows application

Please mark the thread as solved
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Simple algorithm for making a PictureBox toggle between two pictures on Click_event.
Next Thread in C# Forum Timeline: hi





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC