473,386 Members | 1,745 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.

question regarding redirecting through code...

hi there,

i have an <asp:button> control on my webpage that when clicked, i want to
redirect the HTTP request to an EXE file, but instead of actually directing
the browser and address bar to there, i only want the SaveAs box to appear,
to download the file, and the actual web page to remain the same.

VB.NET example would be greatly appreciated.

Thanks,
Paul.

Nov 18 '05 #1
2 1092
Use Response.Redirect(fileName); on Button Click event.
Nov 18 '05 #2
Ian
I dont do VB.NET, but I made a page that does effectively what you
ask:

You'll need to set the content-type as appropriate (or
application/octet-stream or whatever) and most of the junk in the
middle is to support resuming downloads, but basically make an empty
ASPX page with this Page_Load and then pass the relative path to the
file you want to force download on the query string (i.e.
forceDownload.aspx?File=~/foobar/baz.pdf -- URLEncoded of course)

private void Page_Load(object sender, System.EventArgs e)
{
string webAppPath = Request.Params["File"];
string fileMapPath;
try
{
fileMapPath = Server.MapPath(webAppPath);
}
catch { return; }

if (!File.Exists(fileMapPath))
return;

FileInfo infoAboutFile = new FileInfo(fileMapPath);
long startPos = 0, fileSize, endPos;
fileSize = infoAboutFile.Length;
endPos = fileSize;

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();

string range = HttpContext.Current.Request.Headers["Range"];
if (range != null && range.Length > 0)
{
string[] startEnd =
range.Substring(range.LastIndexOf("=")+1).Split('-');
if (startEnd[0].Length > 0)
startPos = Convert.ToInt32(startEnd[0]);

if (startEnd.GetUpperBound(0) >= 1 && startEnd[1].Length > 0)
endPos = Convert.ToInt32(startEnd[1]);
else
endPos = fileSize - startPos;

if (endPos > fileSize)
endPos = fileSize - startPos;

HttpContext.Current.Response.StatusCode=206;
HttpContext.Current.Response.StatusDescription="Pa rtial Content";
HttpContext.Current.Response.AppendHeader("Content-Range", "bytes "
+ startPos.ToString() + "-" + endPos.ToString() + "/" +
fileSize.ToString());

}

if (startPos == 0)
HttpContext.Current.Response.ContentType = "application/pdf";

HttpContext.Current.Response.AppendHeader("Content-disposition","attachment;
filename=" + infoAboutFile.Name);
HttpContext.Current.Response.WriteFile(fileMapPath , startPos,endPos);
HttpContext.Current.Response.End();
}

The key to doing what you want to do here is the
content-disposition:attachment header which will force modern browsers
to download instead of attempting to display or hand off to other app.

Hope that helps
Ian

"Paul M" <mi******@hotmail.com> wrote in message news:<eC**************@tk2msftngp13.phx.gbl>...
hi there,

i have an <asp:button> control on my webpage that when clicked, i want to
redirect the HTTP request to an EXE file, but instead of actually directing
the browser and address bar to there, i only want the SaveAs box to appear,
to download the file, and the actual web page to remain the same.

VB.NET example would be greatly appreciated.

Thanks,
Paul.

Nov 18 '05 #3

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

Similar topics

2
by: Stijn Goris | last post by:
Hi all, I have a question regarding the header function. I send a browser to a certain page (eg first.php ) wich sends no output to the browser. This page sends the browser to another page (eg...
10
by: Kenneth Keeley | last post by:
Hi, I have been having problems with Gecko based browsers not redirecting properly. This is the line of code that does the redirecting: Response.Redirect ("Validation.asp?BookingNo=1234567") ...
0
by: Christophe HELFER | last post by:
hi, I have some problem with redirecting input and output from a process. I can only use VB language (sorry...) Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) ...
3
by: lozd | last post by:
Would appreciate any solutions people could offer for this. Basically I wan't to use a frameset with an aspx page as the contents rather than a htm page and I'd like to be able to redirect the...
1
by: Bilbo | last post by:
Hello, How do I programatically redirect a page in "another frame" using C# in ASP.NET? Server.Transfer redirects the current page...not a different frame. Thanks.
14
by: Mike | last post by:
I have a routine that i only want to execute if a variable is set to Y. The routine is getting some information on the screen then redirecting to a new page. How can i passed a variable to the...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
6
by: Christophe Helfer | last post by:
hi, I have some problem with redirecting input and output from a process. Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) command line utility as redirecting its...
6
by: Jon | last post by:
All, I'm working in a fairly robust content management system for our company's websites, and have a question regarding the file and directory structure of the site. Currently, I'm populating...
17
by: mansb2002 | last post by:
Hi, We recently moved our webserver from Win2K to Win2003. The application works fine. Only problem is that when user views a report as a PDF, IE does not show it. The following code is used 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
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,...

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.