asp-classic
  • stream
  • on-the-fly
  • 2017-03-02 96 views 0 likes 
    0

    我需要使用傳統的asp動態創建和發送TXT文件。我知道如何創建這個文件保存到一個目錄,然後發送它使用Server.CreateObject(「ADODB.Stream」)...但我想要的是避免將其保存在目錄中,只是創建和發送即時。 在這種情況下,TXT文件是從MySql DB提取的記錄列表。其中每行...ASP流發送一個動態創建的TXT文件

    strSQL = "SELECT * FROM mydb WHERE condition='ok';" 
    Set rs = my_conn.Execute(strSQL)  
    
        Response.Buffer = False 
        Dim objStream 
        Set objStream = Server.CreateObject("ADODB.Stream") 
        objStream.Type = 1 'adTypeBinary 
        objStream.Open 
        Response.ContentType = "application/x-unknown" 
        Response.Addheader "Content-Disposition", "attachment; filename=recordsfile.txt" 
        Response.BinaryWrite (dunno how to create a file with rs("field01") & " _ " & rs("field02") & vbnewline 
        objStream.Close 
        Set objStream = Nothing 
    

    是否有可能做到這一點...這意味着在內存中創建一個文件中sTREM /送... orthere是別無選擇,只能創建和保存在磁盤上之前和之後發送??

    回答

    0

    以下將工作。注意:下面的示例假定您的記錄集返回一個字段。

    strSQL = "SELECT * FROM mydb WHERE condition='ok';" 
    Set rs = my_conn.Execute(strSQL) 
    
    if not rs.eof then 
    
        response.contentType = "application/octet-stream" 
    
        response.addHeader "Content-Disposition", "attachment; filename=recordsfile.txt" 
    
        do until rs.eof 
         response.write rs(0).value & vbcrlf 
         rs.movenext 
        loop 
    
    end if 
    
    相關問題