【问题标题】:how to convert string to byte array in Classic ASP如何在经典 ASP 中将字符串转换为字节数组
【发布时间】:2020-09-21 14:39:04
【问题描述】:

我正在尝试以经典 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 页面时,它显示为字符串...我想将字符串转换为字节数组并将该数组传递给Response.BinaryWrite(need to pass byte)

【问题讨论】:

    标签: vbscript asp-classic


    【解决方案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
    

    【讨论】:

      【解决方案2】:
      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;      
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-29
        • 1970-01-01
        相关资源
        最近更新 更多