When users submit a Form with a SQL query, the resultset is retrieved
from a MS-Access database table which is then exported to an MS-Excel
worksheet. After the records get exported to MS-Excel, I want to give
users the option to download the Excel file to their local machine. In
other words, when users click a download link, I want the Save As..
dialog box to pop-up so that users can save the Excel file to their
local machine (note that I don't want users to view the Excel
worksheet in their browser). This is how I tried it:
<%
Dim strFile
'here strFile is just the file name & does not include it's
physical path
strFile=Request("file")
Response.ContentType="application/octetstream"
Response.AddHeader "Content-Disposition","filename=" & strFile
Dim objStream
strFile=Server.MapPath(strFile)
Set objStream=Server.CreateObject("ADODB.STREAM")
objStream.Open
objStream.Type=1
objStream.LoadFromFile(strFile)
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream=Nothing
%>
The above code doesn't give users the option to save the Excel file in
their local machines. Rather the Excel worksheet opens in the browser.
What am I doing wrong here?
What I find is if I pass the PHYSICAL PATH of the Excel file to the
LoadFromFile method, say, something like C:\Inetpub\wwwroot\XL
\XLFile.xls & change the above code slightly to look like this:
<%
Dim strFile,strFileName
strFile=Request("file")
strFile="C:\Inetpub\wwwroot\XL\" & strFile
'just get the file name; exclude it's path
strFileName=Right(strFile,Len(strFile)-InStrRev(strFile,"\"))
Response.ContentType="application/octetstream"
Response.AddHeader "Content-Disposition","filename=" & strFileName
Dim objStream
Set objStream=Server.CreateObject("ADODB.STREAM")
objStream.Open
objStream.Type=1
objStream.LoadFromFile(strFile)
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream=Nothing
%>
In the 2nd code, I am passing the file name as well as it's entire
PHYSICAL PATH to the LoadFromFile method & this does pop-up the Save
As... dialog box so that users can download the Excel file to their
local machines.
But in the 1st code, I am passing the file name along with it's
VIRTUAL PATH to the LoadFromFile method. Hence to get the PHYSICAL
PATH, I am using Server.MapPath but the Excel file opens up in the
browser & doesn't pop-up the Save As.. dialog box. 1 7423
On Apr 4, 4:55 am, r...@rediffmail.com wrote:
When users submit a Form with a SQL query, the resultset is retrieved
from a MS-Access database table which is then exported to an MS-Excel
worksheet. After the records get exported to MS-Excel, I want to give
users the option to download the Excel file to their local machine. In
other words, when users click a download link, I want the Save As..
dialog box to pop-up so that users can save the Excel file to their
local machine (note that I don't want users to view the Excel
worksheet in their browser). This is how I tried it:
<%
Dim strFile
'here strFile is just the file name & does not include it's
physical path
strFile=Request("file")
Response.ContentType="application/octetstream"
Response.AddHeader "Content-Disposition","filename=" & strFile
Dim objStream
strFile=Server.MapPath(strFile)
Set objStream=Server.CreateObject("ADODB.STREAM")
objStream.Open
objStream.Type=1
objStream.LoadFromFile(strFile)
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream=Nothing
%>
The above code doesn't give users the option to save the Excel file in
their local machines. Rather the Excel worksheet opens in the browser.
What am I doing wrong here?
What I find is if I pass the PHYSICAL PATH of the Excel file to the
LoadFromFile method, say, something like C:\Inetpub\wwwroot\XL
\XLFile.xls & change the above code slightly to look like this:
<%
Dim strFile,strFileName
strFile=Request("file")
strFile="C:\Inetpub\wwwroot\XL\" & strFile
'just get the file name; exclude it's path
strFileName=Right(strFile,Len(strFile)-InStrRev(strFile,"\"))
Response.ContentType="application/octetstream"
Response.AddHeader "Content-Disposition","filename=" & strFileName
Dim objStream
Set objStream=Server.CreateObject("ADODB.STREAM")
objStream.Open
objStream.Type=1
objStream.LoadFromFile(strFile)
Response.BinaryWrite(objStream.Read)
objStream.Close
Set objStream=Nothing
%>
In the 2nd code, I am passing the file name as well as it's entire
PHYSICAL PATH to the LoadFromFile method & this does pop-up the Save
As... dialog box so that users can download the Excel file to their
local machines.
But in the 1st code, I am passing the file name along with it's
VIRTUAL PATH to the LoadFromFile method. Hence to get the PHYSICAL
PATH, I am using Server.MapPath but the Excel file opens up in the
browser & doesn't pop-up the Save As.. dialog box.
OK....I got it. The line
Response.AddHeader "Content-Disposition","filename=" & strFile
should read as
Response.AddHeader "Content-Disposition","attachment;filename=" &
strFile This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: joseph.inglis |
last post by:
I have a web browser object on a form which I have set to edit mode and use
the UCOMIConnectionPointContainer interface to hook in and catch events.
All working sweetly.
Except there...
|
by: Alvo von Cossel I |
last post by:
hi,
i have a textbox in a form. when you press a Save button, a savefiledialog
appears. creating ther file works but everytime you click save, the dialog
appears. how do i make the dialog appear...
|
by: John |
last post by:
Hi,
I generate a report in a comma delimited file and give it
a name like MyReport.csv . I then set a Hyperlink
control to point tp the file
HyperLink1.text = "Download"...
|
by: Richard |
last post by:
Hi
I'm new to ASP/Web programming so any help would be appreciated...
Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. ...
|
by: Dune |
last post by:
Hi there,
I have an aspx page that allows users to enter several parameters using drop downs and text boxes. The users then press a button that produces an extract based on the parameters they...
|
by: M Pearson |
last post by:
Hello there all, am very new to asp.net programming and am struggling
with this problem.
What I trying to achieve.
On a button click I want the standard web save as dialog to display.
The user...
|
by: =?Utf-8?B?YXNkZg==?= |
last post by:
Hello. I am making a web application with c# and am using this code:
Response.ContentType = "application/x-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" +...
|
by: vbaDev |
last post by:
Hi. I am using Access 2000 and in my code I'm exporting a table into an Excel file (creating it), then the code needs to export another query into the same file (a new worksheet). So I needed both a...
|
by: paquer |
last post by:
I'd like to provide an Export Function from my forms, where the User
can choose the File name & save location
Although I cannot get the "Save As" dialog box to open properly from
access.
What is...
|
by: ppardi |
last post by:
I'm developing an addin for Word 2007 and I need to determine whether a user
saves a Word 2007 document in an older format (97-2003) after a save as is
done. The scenario is that the user starts...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |