Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP page to open/download a file

Reply
Thread Tools

ASP page to open/download a file

 
 
Matt
Guest
Posts: n/a
 
      09-04-2004
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!!


 
Reply With Quote
 
 
 
 
Steven Burn
Guest
Posts: n/a
 
      09-04-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!!
>
>



 
Reply With Quote
 
 
 
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      09-04-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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!!
>
>



 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      09-04-2004
..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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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



 
Reply With Quote
 
Steven Burn
Guest
Posts: n/a
 
      09-04-2004
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 \ )).

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:(E-Mail Removed)...
> .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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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

>
>



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      09-04-2004
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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> 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"


 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      09-04-2004
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      09-04-2004
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]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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"


 
Reply With Quote
 
Steven Burn
Guest
Posts: n/a
 
      09-04-2004
I have to same problem Bob........ \

--

Regards

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

Keeping it FREE!


"Bob Barrows [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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]" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> >> 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"
>
>



 
Reply With Quote
 
Ray Costanzo [MVP]
Guest
Posts: n/a
 
      09-04-2004
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Java Script File with Asp.Net page that uses a Master page. Larry Rebich ASP .Net 1 12-02-2006 12:43 AM
ASP Page display the previous page file name in address bar mxia ASP .Net 0 05-19-2006 03:06 PM
asp submitted to process asp;but calling asp page says:"Page not found" aftr 1hr Divya ASP General 2 05-11-2004 09:07 AM
how ASP.NET page gets user input from another ASP.NET page?? Matthew Louden ASP .Net 4 11-24-2003 06:59 AM
Calling a html page from an asp page then returning to the next statement on the original asp page Chuck ASP General 0 07-05-2003 02:00 AM



Advertisments