recently an ex-colleague of mine wanted to send a vfp9 form over the internet through web. his initial method was to compress (zip) the vfp9 form files (scx and sct) the then launch a download process on the client side to download the zip file. but he thought why go through all the “trouble” of zipping and downloading when it would be "cooler" to send the vfp9 form files via xml. by converting the files (scx and sct) to strings and storing these in memo fields of a cursor and in turn convert the cursor to xml he then can send the files through the internet without zipping these first but he ran into a stumbling block. the form he wanted to send contained several activex controls and using the filetostr() function posed a problem.

the form files could not be re-converted back to their original states once these have been embedded into memo fields and converted to xml using the powerful cursortoxml() and xmltocursor() functions. his flat-mate who is incidentally my colleague mentioned to me his predicament. since i had some slack time, i set out to try to help him. i remembered during my development of an email application i did several years ago, that email attachments are encoded/decoded to/from base64 and then attached. so i used the same technique. i used strtofile() to convert the files to strings and then encode these strings to base64 using strconv() and then the embed resulting strings to memo fields. after that convert the cursor to xml and back to cursor and to form files again and guess what it worked like a charm. below is the code i used to achieve this.

set safety off

use in select("cursmyform")

create cursor cursmyform (cfilename c(25),mfile m)

lcformname = "frmmyform"

m.cfilename = forceext(lcformname,"scx")
m.mfile = strconv(filetostr(m.cfilename),13) && encode to base64
insert into cursmyform from memvar
m.cfilename = forceext(lcformname,"sct")
m.mfile = strconv(filetostr(m.cfilename),13) && encode to base64
insert into cursmyform from memvar

cursortoxml("cursmyform","myform.xml",3,512)
xmltocursor("myform.xml","curstemp",512)

select curstemp
scan
	lcnewfilename = forceext(juststem(alltrim(cfilename)) + "_new",justext(alltrim(cfilename)))
	lcnewfile = strtofile(strconv(mfile,14),lcnewfilename) && decode memo then convert to file
endscan

Leave a Reply

Your email address will not be published. Required fields are marked *