I moved from Foxtrails framework to ActiveVFP because some errors with COM. I am trying to send a file, but I am having trouble writing the contents of a file to the response in ActiveVFP.
In Foxtrails I used in default.aspx
In ActiveVFP I tried to write in main.prg:
oResponse.ContentType = "application/octet-stream"
It works for a text file, but for a binary file (zip archive) it returns only the first couple of bytes.
I think oResponse does not have the WriteFile
from asp.net method because I receive the error
Caught .NET exception, source: <B>MAIN.PRG</B> 00009ag90004 err#= 1426 line= 53 OLE error code 0x80020006: Unknown name.1426
OLE error code 0x80020006: Unknown name.
I also tried with oResponse.BinaryWrite
, but on the client I get a corrupt zip file double in size. I checked it with a hex editor and I saw double bytes instead of single bytes.
I use Windows 7 Ultimate 32 bit.
Apr 23, 2014 at 8:44 AM
Edited Apr 23, 2014 at 8:46 AM
I did a search of Discussions and found
which has oResponse.BinaryWrite near the bottom :
SET COMPATIBLE ON
SET COMPATIBLE &lcOldComp
oResponse.AddHeader("Content-Disposition", strcon("attachment; filename="+lcFileName,9))
If that doesn't work,
Generally, ALL classic ASP methods should work as they do in the original classic ASP. However, if the original classic ASP method is not sub-classed in activevfp.prg (see source code), then you have to refer to the object twice in order to make it work. For
example, oResponse.oResponse.BinaryWrite. (if you look at the source you may notice that oRequest has BinaryWrite sub-classed but not oResponse. Therefore, I'm surprised oResponse.BinaryWrite(lcr) worked in the example above))
Thank you very much, Claude! It worked like a charm :)
I think I searched the discussions for "WriteFile", but not for "BinaryWrite". I searched "BinaryWrite" on the net for examples.
I even disabled the handlers in web.config and did some tests with a default.aspx file and I manual called process(), but I end up with other problems.
<% @Page Language="C#" ASPCompat="true" %>
<% @Import Namespace="activevfp_dotnetproxy" %>
server x ;
x = new server() ;
string lcFile = x.Process(Request.Url.AbsoluteUri, Request.FilePath) as string;
Response.Write("Caught XXX .NET exception, source: " + ex.Source + " message: " + ex.Message);
Jun 14 at 6:03 PM
Same thing can be done using VFP CREATEBINARY:
My current problem is that in Chrome, this works only for "attachment"; if I change to "inline", the pdf never finish loading on the browser. It works ok in IE and Safari, but not on Chrome.
Jun 14 at 6:17 PM
FInally solved it:
oResponse.Buffer = .T.
oResponse.contentType = pcContentType
oResponse.AddHeader("Content-Disposition", STRCONV(pcDisposition + [; filename=] + JUSTFNAME(pcFileName),9))
oResponse.CharSet = "UTF-8"
In my case, the key was to remove an extra header that caused the problem on chrome.