how to open and text file on web from windows application

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2008
Posts: 9
Reputation: mrkcse is an unknown quantity at this point 
Solved Threads: 0
mrkcse mrkcse is offline Offline
Newbie Poster

how to open and text file on web from windows application

 
0
  #1
Nov 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

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

 
0
  #2
Nov 12th, 2008
google is your friend.


Check httpwebresponse and httpwebrequest
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 172
Reputation: Jugortha is an unknown quantity at this point 
Solved Threads: 16
Jugortha Jugortha is offline Offline
Junior Poster

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

 
0
  #3
Nov 12th, 2008
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();
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 9
Reputation: mrkcse is an unknown quantity at this point 
Solved Threads: 0
mrkcse mrkcse is offline Offline
Newbie Poster

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

 
0
  #4
Nov 13th, 2008
Thanks for the replies.

I got the solution this way...

  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();
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

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

 
0
  #5
Nov 13th, 2008
Please mark the thread as solved
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC