Link to home
Start Free TrialLog in
Avatar of sgriffin
sgriffinFlag for Ireland

asked on

Saving Excel File - CreateTextFile(Server.MapPath("file.csv")).How to ask user for save location?

Hi at the moment im using the above to save a file to the web server and then its picked up by the user form a hyperlink.

How do i get it so the user is asked for a "save location" and not have the file saved on the PC?

thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of nilapenn
nilapenn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sgriffin

ASKER

what exactly should that give me?
This is my code , do you know where i could put your code?

Im new to asp as youll prob notice !


thanks for your suggestion !




<html>

<head>
<title>IC SHOW F27</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
</head>
<% funloc = request.form("funloc")

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(Server.MapPath("file.csv"))

strProvider="Driver=Microsoft Access Driver (*.mdb); DBQ=d:\sg\training\icweb.mdb;"

strQuer4="SELECT * from main WHERE yourac=" & "'" & Funloc & "'"

set rstfacility = Server.CreateObject("ADODB.Recordset")'


     rstfacility.Open strQuer4, strProvider
Response.Write "<TABLE BORDER='1'>"
Do while NOT rstfacility.EOF
facilityname=rstfacility(0)
facilityname1=rstfacility(1)
facilityname2=rstfacility(2)
facilityname3=rstfacility(3)
facilityname4=rstfacility(4)
facilityname5=rstfacility(5)
facilityname6=rstfacility(6)
facilityname7=rstfacility(7)




Response.Write "<TR><TD bgcolor='#FF8080'>" & facilityname1 & "</TD>"
Response.Write "<TD>" & facilityname2 & "</TD>"
Response.Write "<TD>" & facilityname3 & "</TD>"
Response.Write "<TD>" & facilityname4 & "</TD>"
Response.Write "<TD>" & facilityname5 & "</TD>"
Response.Write "<TD>" & facilityname6 & "</TD>"
Response.Write "<TD>" & facilityname7& "</TD></TR>"



objTextFile.WriteLine facilityname1 & "," & facilityname2 & "," & facilityname3 & "," & facilityname4 & "," & facilityname5 & "," & facilityname6 & "," & facilityname7

rstfacility.MoveNext
 Loop
Response.Write "</TABLE><BR>"

response.write "<br><br><font face=verdana size=2><a href ='javascript:history.go(-1);'>Click here to go back</a><br><br>"


response.contenttye="text/csv"
response.addheader "content-disposition","attachment;filename=myfile.csv"
response.write "whateveryouwant"



response.write "<a href='file.csv'>Save this Entry as an Excel File"

%>

<body background="bckgrnd.jpg" bgproperties="fixed">
</body>
</html>
Hi ive tried that and it doesnt show up as excel , the example on the devx could be what im looking for but when i use the same code , it just shows up on html , no excel , even when using your suggestion.....
just to get the URL here...


http://www.devx.com/webdev/discussions/101001/default.asp


it works fine for me, loads up Excel, not sure why it wouldn't for you?

BRUNO
WHere do i paste the code , ive tried and get this:

Response object error 'ASP 0156 : 80004005'

Header Error

/sgtest/ic/xl.asp, line 4

The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.


Any idea?
chances are you are writing the response.contentType too far down on the page...

any asp line that starts with "response" generally should go at the top...make sure there is no extra code above that line, and try again...

GOod luck!