Ciao, ho un problema che non riesco a risolvere.
Tramite ASP esporto in XML una serie di dati contenuti in un DB MySQL.
I dati sono tanti ed ho pensato di includere nello script ASP il classico msg «Please Wait», ma ottengo questo errore mai visto prima:
Riga errore:codice:Response object error 'ASP 0156 : 80004005' Header Error /____EsportazioneXML/_IncludeXMLtoCSV.asp, line 157 The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
codice:Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Questa è la pagina ASP:
codice:<%@LANGUAGE="VBSCRIPT"%> <% Session.LCID = 1040 Session.Timeout = 200 Response.Buffer = True Set cn = Server.CreateObject("ADODB.Connection") cn.Open "DRIVER={MySQL ODBC 5.1 Driver};SERVER=......;" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Nuova pagina 1</title> </head> <body> <div id="splash" style="position:absolute; top:25%; z-index:1"> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td align="center"> <p align="center"> </p> <p align="center"> [img]../img/ajax-loader-vincenzo.gif[/img]</p> <p align="center" style="margin-top: 0; margin-bottom: 0"> <font face="Verdana" color="#800000" style="font-size: 9pt">Attendere, prego...</font></p> <p align="center" style="margin-top: 0; margin-bottom: 8"> <font face="Verdana" color="#800000" style="font-size: 9pt">La ricerca dei dati richiesti è in corso...</font></p> </td> </tr> </table> </div> <% Response.Flush() %> <% SQL = "SELECT * FROM tabellaProva "%> <% Set Rs = CreateObject("ADODB.Recordset") Rs.Open SQL, cn if not Rs.eof then Rs.Save xmlDoc, 1 xmlDoc.Save Server.MapPath("____EsportazioneXML/prova.xml) end if Rs.Close() Set Rs = Nothing %> <% Set oDOM = CreateObject("MSXML2.DOMDocument.4.0") oDOM.async = False oDOM.Load Server.Mappath("____EsportazioneXML/prova.xml) Set oXSL = CreateObject("MSXML2.DOMDocument.4.0") oXSL.async = False oXSL.Load Server.Mappath("____EsportazioneXML/Trasform_csv.xsl") strTransform = oDOM.transformNode(oXSL) Set fso = CreateObject("Scripting.FileSystemObject") strPath = Server.Mappath("____EsportazioneXML/ & Session.SessionID & ".xls") Session("FileName") = Server.Mappath("____EsportazioneXML/" & Session.SessionID & ".xls") Set file = fso.opentextfile(strPath, 2, True) file.write replace(strTransform, "_", " ") file.Close() Set file = Nothing Set fso = Nothing Set oDOM = Nothing Set oXML = Nothing Set oXSL = Nothing %> </body> <script language="JavaScript"> document.getElementById('splash').style.visibility = "hidden"; </script> </html> <% cn.Close() Set cn = Nothing %> <% strFilePath = Session("FileName") Set oFso = CreateObject("Scripting.FileSystemObject") Set oFile = oFso.GetFile(strFilePath) strFileName = UCase(oFile.Name) strFileSize = CLNG(oFile.size) Set oFile = Nothing Set oFso = Nothing Const adTypeBinary = 1 Response.Clear Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = adTypeBinary objStream.LoadFromFile strFilePath strFileType = lcase(Right(strFileName, 4)) Select Case strFileType Case ".asf" ContentType = "video/x-ms-asf" Case ".avi" ContentType = "video/avi" Case ".doc" ContentType = "application/msword" Case ".zip" ContentType = "application/zip" ContentType = "application/x-zip-compressed" Case ".xls" ContentType = "application/vnd.ms-excel" Case ".gif" ContentType = "image/gif" Case ".jpg", "jpeg" ContentType = "image/jpeg" Case ".wav" ContentType = "audio/wav" Case ".mp3" ContentType = "audio/mpeg3" Case ".mpg", "mpeg" ContentType = "video/mpeg" Case ".rtf" ContentType = "application/rtf" Case ".htm", "html" ContentType = "text/html" Case ".asp" ContentType = "text/asp" Case Else ContentType = "application/octet-stream" End Select Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName Response.AddHeader "Content-Length", strFileSize Response.Charset = "UTF-8" Response.ContentType = ContentType Do While Not objStream.EOS Response.BinaryWrite objStream.Read(8192) Response.Flush Loop objStream.Close Set objStream = Nothing %> <% Set fs = Server.CreateObject("Scripting.FileSystemObject") if fs.FileExists(Session("FileName")) then fs.DeleteFile(Session("FileName")) end if if fs.FileExists(Server.MapPath("____EsportazioneXML/" & filename & "")) then fs.DeleteFile(Server.MapPath("____EsportazioneXML/" & filename & "")) end if set fs = nothing %>

Rispondi quotando