如何在经典ASP中将字符串转换为字节数组

问题描述

我正在尝试使用经典ASP下载文件。 请找到以下代码

set fileDownloadResponse = WebService_FileDownload(FileUri.Value)
Response.ContentType = admindata("FileType")//type getting from sql column
response.addheader "Content-disposition","attachment;filename=""" & FileName & """"
Response.BinaryWrite(fileDownloadResponse.value)//**fileDownloadResponse.value** 

我从代码中以Byte[]返回,但是当它进入ASP页面时,它显示为字符串...我想将字符串转换为Byte Array并将该数组传递到{{1} }。

解决方法

尝试使用ADO Stream Object

Const adTypeBinary = 1
Response.Buffer = False
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
' depends on what fileDownloadResponse is 
' you might need to use .Read(),.ReadText() or .LoadFromFile()
objStream.ReadText fileDownloadResponse.value 
Response.ContentType = "application/x-unknown" ' what kind of file it is?
Response.Addheader "Content-Disposition","attachment; filename=""" & FileName & """"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
,
private HttpResponseMessage DownloadFileResponse( HttpStatusCode statusCode,Byte[] ContentArray )
        {
            HttpResponseMessage response = new HttpResponseMessage();              
            response.StatusCode = statusCode;              
            response.Content = new ByteArrayContent( ContentArray );//here just convert into byte array content and in Response.BinaryWrite (content) pass this content here to get as byte to doqnlaod it.
            return response;      
        }