how to download file using activevfp?

Topics: Developer Forum, Project Management Forum, User Forum
Jun 15, 2008 at 1:28 PM
i try to out binary stream using activevfp,but occurs follow error:

OLE IDispatch ? 0  Response 对象: 007~ASP 0106~类型不匹配~遇到未处理的数据类型?.

my code is:
   LOCAL lcFileName,lcFileSize,lcOldComp,loStream
   lcFileName=JUSTFNAME(lcFile)
   lcOldComp=SET("Compatible")
   SET COMPATIBLE ON
   lcFileSize=FSIZE(lcFile)
   SET COMPATIBLE &lcOldComp
   oResponse.Buffer =.t.
   oResponse.clear()
   oResponse.AddHeader("Content-Disposition", strcon("attachment; filename="+lcFileName,9))
   oResponse.AddHeader("Content-Length",lcFileSize)
   oResponse.ContentType ="application/octet-stream" 
   oResponse.CharSet="UTF-8"
   loStream=CREATEOBJECT("ADODB.Stream")
   loStream.open()
   loStream.type=1
   loStream.LoadFromFile(strcon(lcFile,9))
   strtof(loStream.Read(),"d:\stream.txt")&&for test
   oResponse.BinaryWrite(loStream.Read())
   loStream.close()
   *oResponse.Flush()
   oResponse.end()
who can help me ?



Jun 18, 2008 at 10:14 PM
Can you write out a regular text file successfully?  Do that first to make sure your syntax is correct. 

The error message seems to indicate it's from the ASP script and not your VFP MTDLL which seems sort of strange.  You could possibly google that '007~ASP 0106' message and see how others have dealt with it..

If it were me, I'd try to isolate and find out the line that is causing the problem.
Jun 19, 2008 at 1:40 AM
hi ,claudefox ,thank you very much.

i can't out any file,include regular text, i can download the file,but the downloaded file's length will be 0.

yes,the error not is from mtdll ,but is from the stream object's binarywrite method.
i have google the '0106' error.but i can't resolve the problem.

is there someone do it successful?

Jun 19, 2008 at 12:02 PM
So can you do it successfully from just ASP on that machine?  Make sure you can do it from plain ASP - to see if it really is an ActiveVFP problem or maybe some sort of configuration/permissions problem..

lugreen1 wrote:
hi ,claudefox ,thank you very much.

i can't out any file,include regular text, i can download the file,but the downloaded file's length will be 0.

yes,the error not is from mtdll ,but is from the stream object's binarywrite method.
i have google the '0106' error.but i can't resolve the problem.

is there someone do it successful?




Jun 20, 2008 at 1:59 AM
i can do it successfully from just asp  on the same machine.

following is the asp code:

response.Charset="utf-8"
Response.Expires = -9999
Response.Buffer = True
 '==================================
 'Set oServer = Server.CreateObject("greenFox.Server")
 'Set oServer = oServer.GetDebugObject()
 'Response.BinaryWrite oServer.process()
 'oServer.process()
 'Response.End()
 'set oServer=nothing
 '====================================

lcfile="E:\安装备份\SednaSetup.msi"
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(lcfile)
Response.Clear
Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
Response.AddHeader "Content-Length", objFile.Size
Response.ContentType = "application/octet-stream"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
'-- set as binary
objStream.Type = 1
Response.CharSet = "UTF-8"
''-- load into the stream the file
objStream.LoadFromFile(lcfile)
''-- send the stream in the response
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream = Nothing
Set objFile = Nothing

Jun 21, 2008 at 3:40 PM
Ok, then it must be how VFP is handling the binary write stuff.  I think I had to work with this sort of problem with the ActiveVFP upload class.  Take a look at that and take a look at all the functions you can use in VFP for handling this type of data..
Jul 7, 2008 at 5:12 AM
hi,claudefox,
 i have solve the problem ,the case  of the problem is that i used the ADODB.Stream 's read method twice on time.
now ,i paste the right function :

FUNCTION foutPutFileStream
   PARAMETERS lcFile
   IF !FILE(lcFile)
      *oResponse.write("文件不存在")
      RETURN "文件不存在"
   ENDIF  
   LOCAL lcFileName,lcFileSize,lcOldComp,loStream,lcR
   lcFileName=JUSTFNAME(lcFile)
   lcOldComp=SET("Compatible")
   SET COMPATIBLE ON
   lcFileSize=FSIZE(lcFile)
   SET COMPATIBLE &lcOldComp
   oResponse.Buffer =.t.
   oResponse.clear()
   oResponse.AddHeader("Content-Disposition", strcon("attachment; filename="+lcFileName,9))
   oResponse.AddHeader("Content-Length",lcFileSize)
   oResponse.ContentType ="application/octet-stream"
   oResponse.CharSet="UTF-8"
   loStream=CREATEOBJECT("ADODB.Stream")
   loStream.open()
   loStream.type=1
   loStream.LoadFromFile(strcon(lcFile,9))
   lcR=loStream.Read()
   oResponse.BinaryWrite(lcr)
   loStream.close()
   oResponse.end()
ENDFUNC