?
Solved

How do I Read and parse file from URL. MapPath?

Posted on 2003-02-25
9
Medium Priority
?
584 Views
Last Modified: 2008-03-17
HI All. I am trying to find a way to read in a text file from a URL in ASP. I have tried to use Server.MapPath but that does not work. I am pretty sure that MapPath is for local web server files anyways. Is there a way that I can read in a text file into my ASP page to be parsed using only the URL of the file? THanks
0
Comment
Question by:wauger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 7

Expert Comment

by:chisholmd
ID: 8018888
Not exactly sure what your are asking.  the url of the file?

http://somedomain/thisfile.txt ??

That could be the URL of the file and would probably load it in the browser.

How is the URL going to be formed?  http://somedomain/thisfile.asp ??

and then you'll parse out the name 'thisfile' and combine it with the local path and open it with the FileSystemObject ?

dave

0
 

Author Comment

by:wauger
ID: 8019521
Thanks Dave. Actually, I am trying to receive the same funtionality of the Server.MapPath object and read in a file so that I can parse it and display on screen, but my path is not local, its a URL. I have already tried Server.MapPath("http://internalsite.com/textfile.txt") but that does not work. Any help would be appreciated.
0
 
LVL 7

Expert Comment

by:chisholmd
ID: 8020580
Ahh I think I understand now.  You want you a screen scraper.

You want your script to retrieve a text file from over the internet, take the results and do something with it then redisplay it to the screen.

What you need to do is use the internet transfer control.  I won't go into the details but give you a brief idea of what you can do.

Your script sets up an internet transfer object, you set a few properties like Protocol, URL etc and navigate to the page.  Well actually you assign the results to a striong like:

myBigString = inet.navigate(sURL)


Now you have a string that is the contents of the url. Let me see I think I have some code here somewhere...

Set Inet = Server.CreateObject("InetCtls.Inet.1")
Inet.URL = "http://www.msn.com/"
'Inet.UserName = "MyUserName"
'Inet.Password = "MyPassword"
Inet.AccessType = icDirect
Inet.Protocol = icHTTP
Inet.RemotePort  = 80
Inet.RequestTimeout = 60
strHTMLFile = Inet.OpenURL()
Response.Write(strHTMLFile)
'Response.Write(Inet.ResponseCode)
Set Inet = Nothing

That gives you the basic idea.  It need to be available on your web server.

Do a search on "internet trafer control asp" and you should find all you need.

dave


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:Simongh
ID: 8021981
Inetctls is not thread safe for asp pages. A better solution would to either use the xml components or get the winhttp components from MS.

Using XML to to do http gets is well documented at http://MSDN.microsoft.com

The winhttp components wrap up inetctls in a nice easy to use multi threaded com object. It's well worth getting & free.

Then you do pretty much what chisholmd said.

It's all the docs.
0
 

Accepted Solution

by:
BeefSatay earned 400 total points
ID: 8022620
Here it is .. working code

Now I can't remember which XML you need to install..

Out of memory you will need to install:
 - MSXML3
 - MSXML3 SP1

The following Returns the HTML of the site.

--- START -----

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<%
Dim objHTTP
Dim strSource

CONST GET_URL          = "http://www.google.com"

'     Create the Object
Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

'     Open the connection
objHTTP.Open "GET",GET_URL , False
'     Send
objHTTP.Send

'     Get the Response from the Server
strSource = objHTTP.ResponseText

'     Cleanup
Set objHTTP = Nothing

'     Do a Basic Check
%>
<P><%=Server.HTMLEncode (strSource)%></P>

</BODY>
</HTML>
0
 
LVL 7

Expert Comment

by:chisholmd
ID: 8026440
Thanks Simongh, I wasn't aware of that componant.  I have only used the inet control in VB apps.

Cheers,
Dave
0
 

Expert Comment

by:CleanupPing
ID: 9576864
wauger:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 58

Expert Comment

by:Gary
ID: 9753861
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by BeefSatay

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question