473,386 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ASP page to open/download a file

I want to write a ASP page to open/download a file

In fileview.jsp, I have the file browse, and when user click submit button,
fileview2.asp should open the file.

fileview.asp
============
<FORM ACTION="fileview2.asp" method="POST">
<P><input type="FILE" name="filename">
<P><input type="submit">

fileview2.asp
============
<%
String filename = Request.Form("filename")
Response.Redirect = filename
%>

However, this is not working. any ideas? please advise what I am missing.
thanks!!
Jul 19 '05 #1
12 3492
With what you seem to be decribing, the action that you want to take place
are:

1. User load page with form.
2. User browses for and selects a file.
3. User submits form.
4. File is uploaded to server.
5. Server SAVES file to file system.
6. Browser is redirected to this saved file.

First of all, "String filename = Request.Form("filename")" isn't valid code.
"filename = Request.Form("filename")" would be okay, but that'd just return
the file path that was in the <input type=file> box.

To get the actual file uploaded and saved to the server, you need to use an
upload component.¹ You'd want to use that component to save the file to the
file system and then redirect the user to it.

<sidenote>Why do you want to do this, anyway? It's kinda odd. If I want to
open a file that exists on my file system, my natural reaction would not be
to upload the file to a web site so that it can then turn around and give it
right back to me. But, to each his own.</sidenote>

For handling file uploads, see here:
http://www.aspfaq.com/show.asp?id=2189
Before anything server-side will work for you, make note of the ENCTYPE
value of the form tag.

--------------------------------

Now I'm beginning to thing that you're trying to redirect the user to the
file on his machine. Is this true? If so, I also find this odd, but that's
fine. :] If that's the case, you can do something like this:

<%
if request.form("filename") <> "" Then response.redirect
request.form("filename")
%>

<form method="post" action="default.asp">
<input type="file" name="filename" />
<input type="submit" />
</form>
Ray at home

¹ You can process file uploads without a component and just use pure
VB/Jscripting, but advise against this.
"Matt" <ma*******@hotmail.com> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
I want to write a ASP page to open/download a file

In fileview.jsp, I have the file browse, and when user click submit button, fileview2.asp should open the file.

fileview.asp
============
<FORM ACTION="fileview2.asp" method="POST">
<P><input type="FILE" name="filename">
<P><input type="submit">

fileview2.asp
============
<%
String filename = Request.Form("filename")
Response.Redirect = filename
%>

However, this is not working. any ideas? please advise what I am missing.
thanks!!

Jul 19 '05 #2
Where is the file you are trying to access?

If it's on your server..... check to make sure the path is correct before
re-directing

If it's on the client machine, you've no hope of using redirecting as it
needs to be uploaded to your server first.

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Matt" <ma*******@hotmail.com> wrote in message
news:u0*************@TK2MSFTNGP12.phx.gbl...
I want to write a ASP page to open/download a file

In fileview.jsp, I have the file browse, and when user click submit button, fileview2.asp should open the file.

fileview.asp
============
<FORM ACTION="fileview2.asp" method="POST">
<P><input type="FILE" name="filename">
<P><input type="submit">

fileview2.asp
============
<%
String filename = Request.Form("filename")
Response.Redirect = filename
%>

However, this is not working. any ideas? please advise what I am missing.
thanks!!

Jul 19 '05 #3
..Redirect actually sends an instruction to the browser in the header of the
response, so you can tell a browser to redirect to a file that is local to
the machine. :]

Ray at home

"Steven Burn" <pv*@noyb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Where is the file you are trying to access?

If it's on your server..... check to make sure the path is correct before
re-directing

If it's on the client machine, you've no hope of using redirecting as it
needs to be uploaded to your server first.

--

Regards

Steven Bu

Jul 19 '05 #4
hehe, woops.... (wasn't aware of that one (though to be honest, I've never
had a reason to try it so shouldn't have said there's no hope in the first
place :o\ )).

Ty for the correction ;o)

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:ux**************@TK2MSFTNGP15.phx.gbl...
.Redirect actually sends an instruction to the browser in the header of the response, so you can tell a browser to redirect to a file that is local to
the machine. :]

Ray at home

"Steven Burn" <pv*@noyb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Where is the file you are trying to access?

If it's on your server..... check to make sure the path is correct before re-directing

If it's on the client machine, you've no hope of using redirecting as it
needs to be uploaded to your server first.

--

Regards

Steven Bu


Jul 19 '05 #5
Really? Can you give an example of this? I just made a quick try and
received a "page not found" error. If this is true, its' a huge security
hole isn't it? What's to prevent a hacker from redirecting to an executable
on the user''s machine (if it exists).

Bob

Ray Costanzo [MVP] wrote:
.Redirect actually sends an instruction to the browser in the header
of the response, so you can tell a browser to redirect to a file that
is local to the machine. :]

Ray at home

"Steven Burn" <pv*@noyb.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Where is the file you are trying to access?

If it's on your server..... check to make sure the path is correct
before re-directing

If it's on the client machine, you've no hope of using redirecting
as it needs to be uploaded to your server first.

--

Regards

Steven Bu


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #6
Put this in a page and load it, as an example that'll let you specify what
local file to be redirected to.

<%
if request.form("filename") <> "" Then response.redirect
request.form("filename")
%>

<form method="post" action="default.asp">
<input type="file" name="filename" />
<input type="submit" />
</form>

If you browse to an executable, you'll get prompted to download.
Response.Redirect "C:\windows\notepad.exe"

Ray at home

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Really? Can you give an example of this? I just made a quick try and
received a "page not found" error. If this is true, its' a huge security
hole isn't it? What's to prevent a hacker from redirecting to an executable on the user''s machine (if it exists).

Bob

Jul 19 '05 #7
Hmm, surprisingly, nothing happens. I thought I would get an error, but the
page simply reloads when I click Submit. I used Response.Write to verify
that the page was submitting and it was.

Here's the code:

<%
if request.form("filename") <> "" Then
Response.Write request.form("filename") & "<BR>"
response.redirect request.form("filename")
end if
%>
<html>
<BODY>
<form method="post" action="default.asp" id=form1 name=form1>
<input type="file" name="filename" style="WIDTH: 500px; HEIGHT: 22px"
size=28>
<input type="submit" value="Submit Query">
</FORM></BODY></HTML>

If I comment out the redirect, the response.write occurs.
When I uncomment it, it seems like the default.asp page reloads

Bob Barrows
Ray Costanzo [MVP] wrote:
Put this in a page and load it, as an example that'll let you specify
what local file to be redirected to.

<%
if request.form("filename") <> "" Then response.redirect
request.form("filename")
%>

<form method="post" action="default.asp">
<input type="file" name="filename" />
<input type="submit" />
</form>

If you browse to an executable, you'll get prompted to download.
Response.Redirect "C:\windows\notepad.exe"

Ray at home

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Really? Can you give an example of this? I just made a quick try and
received a "page not found" error. If this is true, its' a huge
security hole isn't it? What's to prevent a hacker from redirecting
to an executable on the user''s machine (if it exists).

Bob


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #8
I have to same problem Bob........ :o\

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
Hmm, surprisingly, nothing happens. I thought I would get an error, but the page simply reloads when I click Submit. I used Response.Write to verify
that the page was submitting and it was.

Here's the code:

<%
if request.form("filename") <> "" Then
Response.Write request.form("filename") & "<BR>"
response.redirect request.form("filename")
end if
%>
<html>
<BODY>
<form method="post" action="default.asp" id=form1 name=form1>
<input type="file" name="filename" style="WIDTH: 500px; HEIGHT: 22px"
size=28>
<input type="submit" value="Submit Query">
</FORM></BODY></HTML>

If I comment out the redirect, the response.write occurs.
When I uncomment it, it seems like the default.asp page reloads

Bob Barrows
Ray Costanzo [MVP] wrote:
Put this in a page and load it, as an example that'll let you specify
what local file to be redirected to.

<%
if request.form("filename") <> "" Then response.redirect
request.form("filename")
%>

<form method="post" action="default.asp">
<input type="file" name="filename" />
<input type="submit" />
</form>

If you browse to an executable, you'll get prompted to download.
Response.Redirect "C:\windows\notepad.exe"

Ray at home

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:ep**************@tk2msftngp13.phx.gbl...
Really? Can you give an example of this? I just made a quick try and
received a "page not found" error. If this is true, its' a huge
security hole isn't it? What's to prevent a hacker from redirecting
to an executable on the user''s machine (if it exists).

Bob


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 19 '05 #9
So, your page also redirected me to my local file. I was testing it at
http://test/localredirect/bob.asp. I then went to
http://test.mydomain.local/localredirect/bob.asp, and I got the same results
you did. So, hmm, I guess IE will redirect to a local file if done so from
the intranet zone but not from the Internet zone! Interesting...

Ray at home

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
Hmm, surprisingly, nothing happens. I thought I would get an error, but the page simply reloads when I click Submit. I used Response.Write to verify
that the page was submitting and it was.

Here's the code:

<%
if request.form("filename") <> "" Then
Response.Write request.form("filename") & "<BR>"
response.redirect request.form("filename")
end if
%>
<html>
<BODY>
<form method="post" action="default.asp" id=form1 name=form1>
<input type="file" name="filename" style="WIDTH: 500px; HEIGHT: 22px"
size=28>
<input type="submit" value="Submit Query">
</FORM></BODY></HTML>

If I comment out the redirect, the response.write occurs.
When I uncomment it, it seems like the default.asp page reloads

Bob Barrows

Jul 19 '05 #10
Strange. I'm doing it on my localhost, which is shown in the browser as
"Local Intranet".

I'm using XP SP2 so maybe that security hole has been closed.

Bob

Ray Costanzo [MVP] wrote:
So, your page also redirected me to my local file. I was testing it
at http://test/localredirect/bob.asp. I then went to
http://test.mydomain.local/localredirect/bob.asp, and I got the same
results you did. So, hmm, I guess IE will redirect to a local file
if done so from the intranet zone but not from the Internet zone!
Interesting...

Ray at home

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...
Hmm, surprisingly, nothing happens. I thought I would get an error,
but the page simply reloads when I click Submit. I used
Response.Write to verify that the page was submitting and it was.

Here's the code:

<%
if request.form("filename") <> "" Then
Response.Write request.form("filename") & "<BR>"
response.redirect request.form("filename")
end if
%>
<html>
<BODY>
<form method="post" action="default.asp" id=form1 name=form1>
<input type="file" name="filename" style="WIDTH: 500px; HEIGHT: 22px"
size=28>
<input type="submit" value="Submit Query">
</FORM></BODY></HTML>

If I comment out the redirect, the response.write occurs.
When I uncomment it, it seems like the default.asp page reloads

Bob Barrows


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #11
I'm now at work where I have gotten around to installing SP2, and same
thing, it does not redirect me to my local file, Internet, intranet, or
trusted sites zone.

On a W2K Advanced Server SP 4, redirecting to a local file works. And
surprisingly, it also redirects on Windows Server 2003.

Ray at work

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Strange. I'm doing it on my localhost, which is shown in the browser as
"Local Intranet".

I'm using XP SP2 so maybe that security hole has been closed.

Bob

Ray Costanzo [MVP] wrote:
So, your page also redirected me to my local file. I was testing it
at http://test/localredirect/bob.asp. I then went to
http://test.mydomain.local/localredirect/bob.asp, and I got the same
results you did. So, hmm, I guess IE will redirect to a local file
if done so from the intranet zone but not from the Internet zone!
Interesting...

Ray at home

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...

Jul 19 '05 #12
You're right: on my W2K work machine, it did browse to the local file.
Incredible.

Bob

Bob Barrows
Ray Costanzo [MVP] wrote:
I'm now at work where I have gotten around to installing SP2, and same
thing, it does not redirect me to my local file, Internet, intranet,
or trusted sites zone.

On a W2K Advanced Server SP 4, redirecting to a local file works. And
surprisingly, it also redirects on Windows Server 2003.

Ray at work

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Strange. I'm doing it on my localhost, which is shown in the browser
as "Local Intranet".

I'm using XP SP2 so maybe that security hole has been closed.

Bob

Ray Costanzo [MVP] wrote:
So, your page also redirected me to my local file. I was testing it
at http://test/localredirect/bob.asp. I then went to
http://test.mydomain.local/localredirect/bob.asp, and I got the same
results you did. So, hmm, I guess IE will redirect to a local file
if done so from the intranet zone but not from the Internet zone!
Interesting...

Ray at home

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:eD**************@TK2MSFTNGP11.phx.gbl...


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 19 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Johnny | last post by:
How do I create a link on a Web page on my hard drive that will run an executable file on my hard drive? For example, let's say I create runpoodle.htm and save it to my hard drive, and let's...
2
by: kevinm3574 | last post by:
So, I'm doing the following in a php script so that I can fire a download dialogue AND redirect the page (after clicking submit in a form). I'm doing it this way because of the problem with...
6
by: Tony K | last post by:
I have the most peculiar problem with an ASP.NET page which we use for downloading a file. When the user clicks on a link, the link points to an ASPX page which downloads the file selected. ...
4
by: MW de Jager | last post by:
Hi I want to make a download link on my ASP page, however if I use a Hyperlink, this just tries to open the file in the browser and does nothing if the file is of an unknown type. If I right...
2
by: Ken Varn | last post by:
I have an ASP.NET page that incorporates the following code on a button press. private void DownloadTag_Command(object sender, CommandEventArgs e) { FileStream fs; String Filename; Filename...
5
by: John A Grandy | last post by:
is it possible to write a vb.net code (intended to run on the client-side) that would invoke an instance of IE, have it download a page from a certain URL, and then pre-populate some of the...
5
by: Neil Rossi | last post by:
I have an issue with a particular ASP page on two web servers. Let's call these servers Dev1 and Beta1. Both Servers are running IIS 5, Windows 2000 SP4 with "almost" all of the latest patches. ...
1
by: Carlo | last post by:
I am trying to seek the following functionality: A user clicks on a download buton I can automatically download a file, but since in the end i must end the response, its either the download or...
8
by: rn5a | last post by:
I have a HTML page named Index.html which is divided into 3 frames. The URL of 2 of the frames are HTML pages but the 3rd frame houses a ASP page. Now when I go to Windows Explorer, navigate to...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.