Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy a file from data on my website
Message
 
To
28/01/2011 19:06:17
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01497730
Message ID:
01497781
Views:
73
Here's but another approach:
PROCEDURE getTheTextFileFromTheServer(oform as Form)
LOCAL lcURL as String,oHTTP as "XML Web Service",lcResponse as String 
IF !CheckInterNetConnection()
   MESSAGEBOX([Cannot connect to MYWEBSITE]+CHR(10)+;
              [Check connection],1+64,[Unable to connect])
ELSE 
   lcURL= "http://www.MYWEBSITE.com/_private/form_results10.txt"
   oHTTP=setXMLHTTP()
   WITH oHTTP
   .open([GET],lcURL,.f.)
   .setRequestHeader("Pragma", "no-cache")
   .setRequestHeader("Cache-Control", "no-cache")
   .send()
   lcResponse=.ResponseText && lcResponse contains the CSV in string format.
   .abort()
   ENDWITH 
   RELEASE oHTTP
ENDIF 
RETURN lcReponse
* PARSE CSV STRING HERE TO DBF or SAVE STRTOFILE(lcResponse."c:\hold\form_results10.txt)
ENDPROC 

PROCEDURE PROCEDURE CheckInterNetConnection() &&---------------------------
#DEFINE FLAG_ICC_FORCE_CONNECTION 0x01
LOCAL lConnected as Logical
DECLARE INTEGER InternetCheckConnection IN wininet STRING lpszUrlSTRING,;
        INTEGER dwFlags, INTEGER dwReserved
lConnected=InternetCheckConnection("http://www.microsoft.com",FLAG_ICC_FORCE_CONNECTION,0)=1
CLEAR DLLS "InternetCheckConnection"
RETURN lConnected
ENDPROC &&CheckInterNetConnection() &&---------------------------

PROCEDURE setXMLHTTP()
LOCAL loHTTP as "XML Web Service",cOnError as String,cHTTP as String
cOnError=ON('ERROR')
ON ERROR loHTTP=.NULL.
cHTTP="MSXML2.ServerXMLHTTP.4.0"
loHTTP=NEWOBJECT("MSXML2.ServerXMLHTTP.4.0")
IF ISNULL(oHTTP)
   ON ERROR oHTTP=.NULL.
   cHTTP="MSXML2.ServerXMLHTTP"
   loHTTP=NEWOBJECT("MSXML2.ServerXMLHTTP")
   IF ISNULL(oHTTP)
      ON ERROR oHTTP=.NULL.
      cHTTP="MSXML2.XMLHTTP"
      loHTTP=NEWOBJECT("MSXML2.XMLHTTP")
   ELSE 
   ENDIF
ELSE 
ENDIF 
ON ERROR &cOnError
RETURN loHTTP
ENDPROC &&setXMLHTTP()
>Hello,
>
>I need to pull information from a website into FoxPro. The information is within a .txt file (comma delimited) on the website server.
>
>Ideally, I'd just like to copy the .txt files on to my hard drive and manipulate them further in FoxPro. When I try to:
>
>copy file "http://www.MYWEBSITE.com/_private/form_results10.txt" to c:\hold\form_results10.txt
>
>I get the error "Invalid path or filename". I tried something else earlier (don't recall what it was) that led me to believe FoxPro was "stuck" within the C:\ drive (something like it couldn't find c:\http://...).
>
>I also tried writing a macro in Excel to open the .txt file there and manipulate it. I'm not sure how to tweak that code to actually work.
>
>If there is a way to just copy the files, that's perfect. If not, help converting the following macro to "FoxSpeak" would be greatly appreciated.
>
>Thanks,
>Martha Kroll
>
>
>Sub Macro1()
>'
>' Macro1 Macro
>' Macro recorded 1/28/2011 by Martha Kroll
>'
>
>'
> ChDir "http://www.rivercitymotorsusedcars.com/_private"
> Workbooks.OpenText Filename:= _
> "http://www.MYWEBSITE.com/_private/form_results10.txt", Origin _
> :=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
> , ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False, Comma:= _
> True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
> Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 3), Array(7, 1)), TrailingMinusNumbers _
> :=True
> Selection.Copy
> Range("A2").Select
> ActiveSheet.Paste
> Range("A1").Select
> Application.CutCopyMode = False
> Selection.EntireRow.Delete
>End Sub
Imagination is more important than knowledge
Previous
Reply
Map
View

Click here to load this message in the networking platform