Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > File Download Dialog on Page Load

Reply
Thread Tools

File Download Dialog on Page Load

 
 
ckarbass@gmail.com
Guest
Posts: n/a
 
      01-27-2007
I'd like for the file download dialog to be launched upon page load.
The workflow or behavior is exactly the same as sourceforge's.

I've searched on google to no avail. Any help would be appreciated.
Thanks.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
Guest
Posts: n/a
 
      01-28-2007
Howdy,

No probs. Different type of content cannot be mixed (well in theory it can,
anyone interested have a look at this topic:
http://groups.google.co.uk/group/mic...8b66ab6b35e3db)
therefore, you must use an iframe inside your main document that will serve
file as in following example:
-- main page aspx code --
<iframe runat="server" id="whatever" src="download.aspx?fileid=123"></iframe>
-- end --

-- download.aspx c# code behind --
public partial class Download : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

// get the file path from query string id
// be careful what you serve, do not allow
// any file to be available
// in my example i added jpeg image copied
// to the application's root folder
string filePath = Server.MapPath("~/sunset.jpg");

System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", String.Format("attachment;
filename=\"{0}\"", filePath));
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.WriteFile(filePath);
Response.End();

}
}
-- end --


Done.

Hope this helps

--
Milosz


"(E-Mail Removed)" wrote:

> I'd like for the file download dialog to be launched upon page load.
> The workflow or behavior is exactly the same as sourceforge's.
>
> I've searched on google to no avail. Any help would be appreciated.
> Thanks.
>
>

 
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
Load a wen page with file information and show save as dialog Stefan Soljemo ASP .Net 3 11-04-2009 07:58 AM
Opening ASP page causes file download dialog instead Neil Rossi ASP General 5 02-07-2006 09:54 PM
Page load of the parent page called twice when a modal dialog is opened from a button click of the user control on the parent page Samy ASP .Net 2 08-15-2005 03:30 PM
Rendering a page handling a File Download Dialog causes page state to belost Nishi Bhonsle Java 0 02-25-2004 02:22 AM
ASP startup page invokes a file download dialog Don Peters ASP General 1 10-26-2003 02:56 AM



Advertisments