473,387 Members | 1,326 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,387 software developers and data experts.

File downloads to client

A few weeks back, a message was posted regarding how to force a file
download to a client. The code for this technique is shown at the end
of this message.

A question I have about this technique is how to gracefully get back
to one's web app after doing the file download? Does one just do the
transfer by opening the download page in a separate browser window and
leave the "empty" browser for the user to close or is there a more
elegant way to handle this?

TIA,

Paul
================================================== ====

private void Page_Load(object sender, System.EventArgs e)
{
string path = Server.MapPath(Request.ApplicationPath +
"/test.acp");
System.IO.FileInfo file = new System.IO.FileInfo(path);

// clear the current output content from the buffer
Response.Clear();

// add the header that specifies the default filename for the
// Download/SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename="
+
file.Name);

// add the header that specifies the file size, so that the
browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());

// specify that the response is a stream that cannot be read by
the
// client and must be downloaded
Response.ContentType = "application/octet-stream";

// send the file stream to the client
Response.WriteFile(file.FullName);

// stop the execution of this page
Response.End();
}
Nov 18 '05 #1
3 1981
when file download is clicked..using javascript open a new window
window.open("yourdownload.aspx")
and in yourdownload.aspx ..put the code to download and just before
Response.End() (code below)
put RegisterStartupScript("closeWindow","<script
language='javascript'>window.close();</javascript>") // closes the window

hth,
Av.

"Gibby" <pa*********@i-stat.com> wrote in message
news:ec**************************@posting.google.c om...
A few weeks back, a message was posted regarding how to force a file
download to a client. The code for this technique is shown at the end
of this message.

A question I have about this technique is how to gracefully get back
to one's web app after doing the file download? Does one just do the
transfer by opening the download page in a separate browser window and
leave the "empty" browser for the user to close or is there a more
elegant way to handle this?

TIA,

Paul
================================================== ====

private void Page_Load(object sender, System.EventArgs e)
{
string path = Server.MapPath(Request.ApplicationPath +
"/test.acp");
System.IO.FileInfo file = new System.IO.FileInfo(path);

// clear the current output content from the buffer
Response.Clear();

// add the header that specifies the default filename for the
// Download/SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename="
+
file.Name);

// add the header that specifies the file size, so that the
browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());

// specify that the response is a stream that cannot be read by
the
// client and must be downloaded
Response.ContentType = "application/octet-stream";

// send the file stream to the client
Response.WriteFile(file.FullName);

// stop the execution of this page
Response.End();
}

Nov 18 '05 #2

I had thought of using a technique similar to what you suggested but
without any success. I believe that it fails because that the info I
put into the header instructs the browser to not to attempt to render
the data stream and this forces the download dialog to appear. In fact,
after the download completes, if I attempt to view the source for the
page, there is none. Additionally, the address line of the browser (IE6)
is blank.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
I do exactly this in a couple of my web applications, but don't have a
problem.

I set the target attribute on the page that calls for the download to _self,
so the browser uses the same window. When the browser gets the response
forcing a download it downloads the file, leaving the original page in
view - no new window to close, no empty window, just what was there before.

Brian Lowe
---------@
"Gibby" <pa*********@i-stat.com> wrote in message
news:ec**************************@posting.google.c om...
A few weeks back, a message was posted regarding how to force a file
download to a client. The code for this technique is shown at the end
of this message.

A question I have about this technique is how to gracefully get back
to one's web app after doing the file download? Does one just do the
transfer by opening the download page in a separate browser window and
leave the "empty" browser for the user to close or is there a more
elegant way to handle this?

Nov 18 '05 #4

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

Similar topics

10
by: StevePBurgess | last post by:
I would like to make my downloads section unbrowsable (to users) but accessible to scripts. Can I deliver a file to a browser without linking to it's URL so that I can deliver files...
21
by: BlackHawke | last post by:
My name is Nick Soutter, I own a small game development company (www.aepoxgames.net) making our first game (www.andromedaonline.net) in java. I am writing because we are having a very...
1
by: Neel Word | last post by:
I need to develop an application (development platform: Win2000; target platform: Win98/ME/NT4/2000/XP), which would require file transfer functionality over dial-up and network. We could...
20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: Jeff Cooper | last post by:
Hey there folks, I have a link on a page which I would like to point to string that's downloaded as a file -- a *.tab file to be exact. The link points to a file (download.aspx) which contains...
6
by: Jatin | last post by:
Hey Guys I have a web application that allows users to download files. But the files are not hosted on the webserver. The files are stored on external servers and are referenced by a URL/URI....
5
by: Simone M | last post by:
Here is my problem: I need to append a string to a file every time the user downloads this file. The string is different for every user. I would like to append the string to the file via ftp. But...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
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,...
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.