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

To download a file from within pb7 script.

I want to run this link by the script of Powerbuilder 7.
I have Internet Explorer.

http://www.moosani.com/pricelst/May2006/12052006.csv

Is it possible to by pass every intermediaries.

I mean, internally, the script would connect to the above link. Save the file into directory D:\download without asking from the user. Etc.
0
Mateen
Asked:
Mateen
  • 5
  • 3
1 Solution
 
diasroshanCommented:
Hi,

guess this is what u want...

String ls_url, ls_filename
Long      ll_ret
inet      linet_main
n_cst_internet     luo_data

linet_main = CREATE inet

luo_data = CREATE n_cst_internet

//THIS.GetContextService("Internet", linet_main)
ls_url = 'http://www.moosani.com/pricelst/May2006/12052006.csv'
ls_filename = Mid(ls_url,Len(ls_url) - 12) //grabbing file name from URl assuming it to b of same length
SETPOINTER(hourglass!)
ll_ret = linet_main.GETURL(ls_url,luo_data)
SETpointer(ARROW!)
IF ll_ret = 1 THEN
     //MessageBox("HTML", String(luo_data.is_data))
              integer li_FileNum
            li_FileNum = FileOpen("C:\"+ls_filename, LineMode!, Write!, LockWrite!, Append!)
            FileWrite(li_FileNum,luo_data.is_data )
ELSE
     //MessageBox("ERROR", String(ll_ret))
END IF

DESTROY luo_data
DESTROY linet_main


Cheers,
Rosh
0
 
diasroshanCommented:
Hi,

in ur case just change the below line
 li_FileNum = FileOpen("C:\"+ls_filename, LineMode!, Write!, LockWrite!, Append!)

To ,

 li_FileNum = FileOpen("D:\Download\"+ls_filename, LineMode!, Write!, LockWrite!, Append!)

Cheers,
Rosh
0
 
diasroshanCommented:
Hi,

missed something important... u need to create a user object

export the following file... copy the below content and save it as n_cst_internet.sru
and export it...

//From here
$PBExportHeader$n_cst_internet.sru
forward
global type n_cst_internet from internetresult
end type
end forward

global type n_cst_internet from internetresult
end type
global n_cst_internet n_cst_internet

type variables
String is_data
end variables
forward prototypes
public function integer internetdata (blob data)
end prototypes

public function integer internetdata (blob data);is_data = string(data)
RETURN 1

end function

on n_cst_internet.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_internet.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
//till here


Cheers,
Rosh
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
MateenAuthor Commented:
Hi dia,

U r genius.

I have one more wish.

I want to save the file "15052006.csv" ( todays' file) as "15052006.txt", I want to rename the extention of the file
from .csv to .txt

Many many thanks

0
 
diasroshanCommented:
Hi,

To save as .txt
change this line
ls_filename = Mid(ls_url,Len(ls_url) - 12) //grabbing file name from URl assuming it to b of same length

To,
ls_filename = Mid(ls_url,Len(ls_url) - 12,9) //grabbing file name from URL assuming it to b of same length

And,
li_FileNum = FileOpen("D:\Download\"+ls_filename, LineMode!, Write!, LockWrite!, Append!)

To,
li_FileNum = FileOpen("D:\Download\"+ls_filename + '.txt', LineMode!, Write!, LockWrite!, Append!)

Thanks for the compliment... feels gr8...
but buddy... im just refering to PB help... nothing else... ;)

Cheers,
Rosh
0
 
MateenAuthor Commented:
Hi dia Roshan,

Sorry , I could not make it clear to where to change the file name. You had to work a lot.

Your code is working great and the downloaded file is being saved into
D:\download\15052006.csv
Once this file name is saved then after that I want to rename the file
D:\download\15052006.csv
as
D:\download\15052006.txt

I did a lot of search in EE Powerbuilder area about this, but, couldnt find any already asked question in this regard






0
 
diasroshanCommented:
Hi,


i have explained it in the above post...

in the code make changes in 2 lines...

To save as .txt
change this line
ls_filename = Mid(ls_url,Len(ls_url) - 12)
To,
ls_filename = Mid(ls_url,Len(ls_url) - 12,9)

And change the following line,
li_FileNum = FileOpen("D:\Download\"+ls_filename, LineMode!, Write!, LockWrite!, Append!)

To,
li_FileNum = FileOpen("D:\Download\"+ls_filename + '.txt', LineMode!, Write!, LockWrite!, Append!)


Hope im clear...

Cheers,
Rosh
0
 
MateenAuthor Commented:
Yes, u r right.
Its ok
Thanks.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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