Hmmm... efter mycket om och men så fungerar det nu.... :)
Jag klistrar in koden, så kan ni se hur jag gjort... anmärka på om något är fel.. eller berömma för att det är snyggt.. ;)
Mvh
Henrik
Sida som genererar textfilen:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<%
If request.Form("supplier") <> "" then
'Definiera variabler
dim objConn, objRS, sSQL, fsObj, tfile, iSupplierId, sUnit, sEndChar, sPath, sFileName, sSupplierName, iCounter
iCounter = 0
'Ta emot data
iSupplierId = cint(request.Form("supplier"))
'Sätta variabler
sEndChar = "X"
sPath = "/createTextFiles/filesForPalm/"
'Funktion
function GetFixedWidthString(stringVal,length)
GetFixedWidthString=left(stringVal & string(length," "),length)
end function
' Öppna databasen
' ***************
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = Application("sConn")
objConn.Open
sSQL = "SELECT supplierName FROM tblSupplier Where supplierId = " & iSupplierId & ""
Set objRS = objConn.Execute (sSQL)
If not objRS.EOF then
sSupplierName = objRS("supplierName")
End If
objRS.Close
Set objRS = Nothing
sFileName = sSupplierName & " - El.txt"
set fsObj=Server.CreateObject("Scripting.FileSystemObject")
set tfile=fsObj.CreateTextFile(server.MapPath(sPath & sFileName))
tfile.WriteLine("[HEADER]")
tfile.WriteLine("<Article.Nr>,8")
tfile.WriteLine("<Article.Price>,8")
tfile.WriteLine("<Article.Unit>,5")
tfile.WriteLine("<Article.Name>,50")
tfile.WriteLine("End,1")
tfile.WriteLine("[DATA]")
sSQL = "SELECT tblArticle.articlenumber, tblArticle.articleName, tblPrice.articlePrice, tblPrice.articleCategoryNumber, tblArticle.articleUnit, " &_
"tblCategory.CategoryName, tblCategory.categoryNumber, tblDiscount.articleDiscount, tblSupplier.SupplierName, tblSupplier.SupplierId, " &_
"CASE WHEN articleDiscount is null THEN articlePrice ELSE articlePrice*(1-([articleDiscount]*0.01)) END AS articlePriceWithDiscount " &_
"FROM tblArticle " &_
"INNER JOIN tblPrice ON tblArticle.articlenumber = tblPrice.articleNumber " &_
"INNER JOIN tblSupplier ON tblPrice.articleSupplierId = tblSupplier.SupplierId " &_
"LEFT OUTER JOIN tblDiscount ON tblPrice.articleCategoryNumber = tblDiscount.categoryNumber AND tblPrice.articleSupplierId = tblDiscount.supplierId " &_
"LEFT OUTER JOIN tblCategory ON tblPrice.articleSupplierId = tblCategory.supplierId AND tblPrice.articleCategoryNumber = tblCategory.categoryNumber " &_
"WHERE tblSupplier.supplierId = " & iSupplierId & " and tblCategory.categoryNumber = '0101' " &_
"ORDER BY tblArticle.articlenumber"
Set objRS = Server.Createobject("ADODB.Recordset")
objRS.Open sSQL, objConn, 1, 2
' Räkneverk
' *********
Response.write("<div id=""message"">Vänta, skriver till databasen...</div>")
Response.write("<div id=""progress""></div>")
Response.Flush()
Do while not objRS.EOF
' Villkor för att flusha
' **********************
iCounter = iCounter +1
if iCounter mod 10 = 0 then
Response.write ("<script>document.getElementById(""progress"").innerHTML=""" & iCounter & """;</script>")
Response.flush
end if
sArticleNumber = GetFixedWidthString(objRS("articleNumber"), 8)
dArticlePrice = GetFixedWidthString(cdbl(objRS("articlePrice")), 8)
sUnit = GetFixedWidthString(objRS("articleUnit"), 5)
sArticleName = GetFixedWidthString(objRS("articleName"), 50)
sLine = sArticleNumber & dArticlePrice & sUnit & sArticleName & sEndChar
tfile.WriteLine(sLine)
objRS.Movenext
Loop
objRS.Close
Set objRS = Nothing
tfile.close
set tfile=nothing
set fsObj=nothing
%>
<script>location.href='getFile.asp?file=<% =sFileName %>';</script>
<%
Response.End()
Else
Response.write "Du har försökt göra en otillåten åtgärd!"
End If
%>
<body>
</body>
</html>
Sida som visar dialogruta "öppna/Spara fil"
<%
sFile = request.querystring ("file")
Set objStream = CreateObject( "ADODB.Stream" )
objStream.Open
objStream.Type = 1
objStream.LoadFromFile server.mappath( "/createTextFiles/filesForPalm/" & sFile )
Response.ContentType = "application/my-download"
Response.AddHeader "Content-Disposition", "attachment; filename=" & sFile &""
Response.BinaryWrite objStream.Read(-1)
Set objStream = nothing
Response.End
%>