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

0 comments:
Post a Comment