sgriffin
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.Fi leSystemOb ject")
Set objTextFile = objFSO.CreateTextFile(Serv er.MapPath ("file.csv "))
strProvider="Driver=Micros oft Access Driver (*.mdb); DBQ=d:\sg\training\icweb.m db;"
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","att achment;fi lename=myf ile.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>
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.Fi
Set objTextFile = objFSO.CreateTextFile(Serv
strProvider="Driver=Micros
strQuer4="SELECT * from main WHERE yourac=" & "'" & Funloc & "'"
set rstfacility = Server.CreateObject("ADODB
rstfacility.Open strQuer4, strProvider
Response.Write "<TABLE BORDER='1'>"
Do while NOT rstfacility.EOF
facilityname=rstfacility(0
facilityname1=rstfacility(
facilityname2=rstfacility(
facilityname3=rstfacility(
facilityname4=rstfacility(
facilityname5=rstfacility(
facilityname6=rstfacility(
facilityname7=rstfacility(
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
response.contenttye="text/
response.addheader "content-disposition","att
response.write "whateveryouwant"
response.write "<a href='file.csv'>Save this Entry as an Excel File"
%>
<body background="bckgrnd.jpg" bgproperties="fixed">
</body>
</html>
could you use a solution like this instead?
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20243109
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20243109
ASKER
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
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
ASKER
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?
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!
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!
ASKER