How to read one line of a text file on a web server using a windows application

FartNocker

Well-known member
Joined
Dec 7, 2003
Messages
97
Location
Western North Carolina
How do I read one line from a text file which is located on a web server using a windows application. I cant seem to find the answers to what I am looking for here. I can display the text file in a browser but this isnt what I want. I just want to read the line and use the data with out using a browser...

Thanks for any Ideas or links,
Mark
 
the simple way?
you may want to use the WebClient class in System.Net to download the file. its very helpful. from that on its either using the byte[] array or saving to a file on disk and using it later on :)
 
Menge said:
the simple way?
you may want to use the WebClient class in System.Net to download the file. its very helpful. from that on its either using the byte[] array or saving to a file on disk and using it later on :)

Thanks for the info... I did try this BUT... All I got was some HTML code that is not a part of the simple text file. The small bit of plain text that is in the file did not come in? Just the HTML headers and stuff you would find associated with a .htm web page.
 
Just tried a test using the following code and it read the first line of the text file correctly.
C#:
 System.Net.WebClient wc = new System.Net.WebClient();
 System.IO.Stream s= wc.OpenRead("http://localhost/test.txt");
 System.IO.StreamReader sr = new System.IO.StreamReader(s);
 string st;
 st=sr.ReadLine();

when you say you received a lot of html - what was the content of the HTML (error message / status code)?
 
PlausiblyDamp said:
Just tried a test using the following code and it read the first line of the text file correctly.
C#:
 System.Net.WebClient wc = new System.Net.WebClient();
 System.IO.Stream s= wc.OpenRead("http://localhost/test.txt");
 System.IO.StreamReader sr = new System.IO.StreamReader(s);
 string st;
 st=sr.ReadLine();

when you say you received a lot of html - what was the content of the HTML (error message / status code)?

First off, thanks for responding. I am getting the correct file but it looks as if it is some how being converted to a html file. A file that only contains the numbers "123456789" and ends in a .txt extension. If I use the webclient to save the file using an .htm extension, then I can double click on it and see the correct contains. But if I view the source code of the saved .htm file I don
 
Last edited by a moderator:
I just converted your example to VB
Code:
Dim wc As New System.Net.WebClient
Dim s As System.IO.Stream = wc.OpenRead(UpdateURL)
Dim sr As New System.IO.StreamReader(s)
Dim st As String
st = sr.ReadLine()
msgbox(st)

And I got enpty string.
 
its probably because your host is embedding all files into a frame for address masking. check if you have that enabled. from the HTML page it seems u accessed the txt file but the host masked it into a framed page.

check that with your web host
 
Last edited by a moderator:
Menge said:
its probably because your host is embedding all files into a frame for address masking. check if you have that enabled. from the HTML page it seems u accessed the txt file but the host masked it into a framed page.

check that with your web host

I called them and that said no about the masking. They sais it was just a stright forward setup. I wonder why when I read the file into a stream I only get an empty String? i.e. ""

Mark
 
I figured out the problem guys. I have a Domain Name which is pointed to my free web space on charter. Using the Domain Name it wont work, but, using the direct address to my free web space on charters servers it works perfect. So in a way you were correct about the masking. It was about to drive me craZY .... LOL Theres always a simple solution, finding it is the hard part. Thanks again guys for the input

Mark
 
Back
Top