Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading Text File over URL 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
0
0
US
I want to open a text file over a URL rather than an actual path. My call in PHP is simply

$filearray = file("
Do I have an equivalent functionality in ASP? I'm just looking to read the file, no need to make any modifications whatsoever.

-Rob
 
use the FileSystemObject object
syntax and methods here
---------------------------------------
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

 
is the file on the same server? ---------------------------------------
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

 
Not exactly... and that's why FileSystemObject hasn't been working for me... and trying to use the UNC is a big ol' pain... so now I've set up the files I need at a URL, and I just need to open the file over that.

-Rob
 
in that case for security reasons I don't think you there is a way to access the file at a outside location as you are. If there is a way you could understand the potential security issues involved.

Why not have all you apples in the same basket [wink]?

I'm supprised any language for that matter would let you access a file like this. ---------------------------------------
{ str = "sleep is good for you. sleep gives you the energy you need to function";
ptr = /sleep/gi;Nstr = str.replace(ptr,"coffee");alert(Nstr); }

 
Yes, as a feature IIS disallows just what I was originally trying to do... but now i serve up the file on a URL, hence alleviating the security concern (since I want it read only, and I've put it out there).

I've found a workaround, namely, I open an ADO string, download the file to a temp directory, and then read it... a little sloppy, but considering I'm talking about 4 line text files not really a performance hit... and I'm hoping if I dig into ADO some more I can just read from the ADO Stream instead of actually copying the file.

And as the the Why not all the apples in the same basket... it's far from my choice, and just not a possibility given the setup here, I'm trying to grab an information file out of a directory structure holding all sorts of data and updates and builds and blah blah for which there's no room on the little server under the desk.

-Rob
 
Well, that work around's not working... what a pain... in PHP it's one line as I posted originally... does anyone out there have an equivalent to that one line?

-Rob
 
Afraid not these all require

CreateObject("Scripting.FileSystemObject")


Which by definition is a server side object.

-Rob
pushing the PHP option at this point
 
Another option is to use the XMLHTTP object to retrieve the contents of the file:
Code:
<%
Response.Buffer = True
Dim objXMLHTTP, URL

' Create an xmlhttp object:
Set objXMLHTTP = Server.CreateObject(&quot;Microsoft.XMLHTTP&quot;)

URL = &quot;[URL unfurl="true"]http://www.google.com/&quot;[/URL]

' Opens the connection to the remote server.
objXMLHTTP.Open &quot;GET&quot;, URL, False

' Actually Sends the request and returns the data:
objXMLHTTP.Send

'Next two lines only for test purposes to print the text contents in ResponseText
'	and force the browser to render it as plain text
Response.ContentType = &quot;text/plain&quot;
Response.Write objXMLHTTP.ResponseText
%>

I included a print out there so you could see it work. The text version of the loaded URL can be retrieved from ResponseText and stored in a variable if need be, or manipulated jusy as you would manipulate any string variable.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
No more vacation for me :(

FAQ FAQ20-2863
= new Forums.Posting.General.GettingAnswers()
 
Yes... XMLHTTP works great. If you are using it on a server though, use this:

Set objXMLhttp = Server.CreateObject(&quot;MSXML2.ServerXMLHTTP&quot;)

This should work for all Windows 2000 IIS servers and Up.
 
Hmmm, Windows 2000 Server, Windows 2000 professional, and my sample works fine on both, what are the advantages to moving to the newer version?

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
No more vacation for me :(

FAQ FAQ20-2863
= new Forums.Posting.General.GettingAnswers()
 
I don't know, but well done... and thanks...

Sensitive code I'm noticing, for those others trying it, you cannot have anything above it whatsoever.

(And this is on NT 4.0 with IIS4 working fine with the original exmaple, modifications however break it)

-Rob
 
The regular &quot;Microsoft.XMLhttp&quot; uses the WinInet API for Windows. It wasn't designed for a heavy load / server applications.

Microsoft goes into detail about it in the XML SDK.
 
You could use one of these components...
ASPTear or ASPHttp This is not a bug - it's an undocumented feature...
;-)
 
skiflyer:modifications however break it
Hmm, they shouldn't. As long as you don't put anything above the Response.Buffer = True then it should be fine. I think that the Response.Buffer line can only be preceded by the language declaration and Option explicit, but I could be wrong and I'm to lazy to double check that one right now. Other than that you should be able to put the xmlhttp code anywhere in the page. In fact that is one way to do mirror checks, check one address, check the return status, uif the status is 200 (opage returned ok) redirect the user, else check status on site2, etc.
This requires multiple calls like the above one and works just fine. Could you post the non-working code?

-Tarwn
Experts are only people who have realized how much they will never know about a language.
________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Sorry, I meant the suggested modifications to use MSXML2.ServerXMLHTTP break it, most likely some installation issue on my end... what you provided is humming along nicely.

-Rob
 
Ok, thanks, I started getting paranoid that I had mis-copied somehow and was to sick this weekend to re-test the code :)

-Tarwn Experts are only people who have realized how much they will never know about a language.
________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
NT4 doesn't have XML 3 installed on it by default like windows 2000. You can download the XML4 package from microsoft.com/xml and the code will work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top