471,595 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

File Download Dialog on Page Load

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.

Jan 27 '07 #1
1 1868
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
"ck******@gmail.com" 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.

Jan 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by peetm | last post: by
reply views Thread by Buddy Ackerman | last post: by
2 posts views Thread by Sleepy | last post: by

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.