• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

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

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
wauger
Asked:
wauger
1 Solution
 
chisholmdCommented:
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
 
waugerAuthor Commented:
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
 
chisholmdCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
SimonghCommented:
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
 
BeefSatayCommented:
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
 
chisholmdCommented:
Thanks Simongh, I wasn't aware of that componant.  I have only used the inet control in VB apps.

Cheers,
Dave
0
 
CleanupPingCommented:
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
 
GaryCommented:
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

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now