 |
|

03-28-2007, 02:15 AM
|
|
SEO Junior
|
|
Join Date: Mar 2007
Posts: 26
|
|
|
Import http Live CSV to DB ???
Is it possible to create a script to import the contence os a CSV or TXT file that is hosted live on the internet straight in to your database without first having to save the file to your computer ?????
If so please could some one point me in the right direction so that i can do it...
|

04-11-2007, 04:26 PM
|
 |
SEO
|
|
Join Date: May 2005
Location: England, UK
Posts: 621

|
|
Hi TommyG
Yes, it's quite simple really.
Code:
Dim URL = "http://www.xyz.com/somefile.txt"
Dim objXMLHTTP
Set objXMLHTTP = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXMLHTTP.Open "GET", URL, False
objXMLHTTP.Send
IF objXMLHTTP.statusText = "OK" THEN
txtFile = objXMLHTTP.responseText
'
'*** Process the content of the file any way you like
'
END IF
'*** Clean up!
Set objXMLHTTP = nothing
The URL can point to any type of file at all, including XML, or even HTML.
You could also do this in Javascript, but you'll get into security context issues if the file being retrieved is not on the local domain - although it's very easy to get around that using a server based proxy script. i.e. Use javascript to call your usual ASP page (which will do the same thing as above), but return the results back to the calling Javascript. You do it that way because the server isn't security restricted.
Doing it this latter way also means you can achieve the desired results without a page refresh. Its actually AJAX - it's very simple.
If you have any problems, let me know.
- BSolveIT
|

04-12-2007, 01:05 AM
|
|
SEO Junior
|
|
Join Date: Mar 2007
Posts: 26
|
|
Nice One BSolveIT, I'll have a go with that today and let you know how i get on
Cheers again!!! 
|

04-12-2007, 01:30 AM
|
|
SEO Junior
|
|
Join Date: Mar 2007
Posts: 26
|
|
Hi BSolveIT, I am hoping you can give me a little more help.
i have 2 live feeds i would like to be able to import in to my database either automaticly or at least without having to go threough all the rigmoral of saving files down and uploading them to my server.
the 2 files are different
1 - http://summitfeed.co.uk/three/three-affil.txt
2 - http://www.three-mobile-phones.com/feeds/bestdeals.csv
I just dont know where to begin with the coding to insert the data from these files in to my DB
specificly How do i split the "objXMLHTTP.responseText" in to usable columns and rows?
My tese page is http://www.three-mobile-phones.com/_Untitled-1.asp
and at present i am experimenting with the code you gave me to see what i can do.
Can you point me in the right direction of any tutorials or similar threads that could help me ???
|

04-12-2007, 03:17 AM
|
 |
SEO
|
|
Join Date: May 2005
Location: England, UK
Posts: 621

|
|
Well, looking at the txt file (I couldn't access the csv file), it appears quite straight forward again. There willl be a few different ways to do this of course, but it all boils down to string manipulation.
Are you familiar with the SPLIT function? Using the SPLIT function, you will be able to read the entire file into an array of lines, then further split each line into an array of elements. Then you'll just need to iterate through and save the values to your database.
Here's an excellent example / tutorial:
http://www.devx.com/asp/Article/16806

|

04-12-2007, 03:20 AM
|
 |
SEO
|
|
Join Date: May 2005
Location: England, UK
Posts: 621

|
|
|
Sorry, I forgot to mention, your going to SPLIT the file into it's lines by splitting on the return character (vbCRLF), but each line will be split into it's elements not on the space character, but on the tab character (vbTAB).
|

04-12-2007, 06:38 AM
|
|
SEO Junior
|
|
Join Date: Mar 2007
Posts: 26
|
|
|
Hi BSolveIT,
I have never used the SPLIT function before but i am going to have a go at that tutorial now.
The other feed is in my own site so i put a password protect on it, I'll take it off now so you can have a look
|

04-12-2007, 06:46 AM
|
 |
SEO
|
|
Join Date: May 2005
Location: England, UK
Posts: 621

|
|
Hi Tommy
Ok, I've looked at the CSV now too. You'll be able to handle it in almost the exact same way. After splitting on the vbCRLF characters to get the lines, split each line at the comma+space. e.g. elements_array = SPLIT(row, ", ")
You'll crack it in super fast time I'm sure.
Let me know how you get on, or if you need more help.

|

04-12-2007, 07:13 AM
|
|
SEO Junior
|
|
Join Date: Mar 2007
Posts: 26
|
|
|
Cheers Mate!!!
|

04-13-2007, 12:57 AM
|
|
SEO Junior
|
|
Join Date: Mar 2007
Posts: 26
|
|
|
Nice One BSolveIT, I am getting the hang of this now,
I think someone tried to explain this to me a while ago but at the time it made No sence at all.
I havent quite done all i want to do but you have deffinately put me on to the right track.
One more question,
Imagine i create scripts to update my database, do you know what would be the way to make these scripts run automaticly in a sequence say either at a set time interval or when the input feed changes (You mentioned in in the first post i think?)?
|
 |
|
| Thread Tools |
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|