0

on my site, i need to display a link, clicking on which should prompt user with Save As dialog so that they can save the file, on there machine instead of seeing the file in browser.

Please any one knows the html code for downloading the Text and HTML file. .txt and .html

Abbas
  • 4,948
  • 31
  • 95
  • 161

2 Answers2

1

You just need to link to the file to be downloaded the rest is handled by the client.

If you are dynamically generating the file in ASP.NET you need to set some additional headers to force a download.

Content-Disposition: attachment; filename=<filename.ext> 

In code:

 Response.AddHeader("content-disposition:","attachment;filename=<filename.ext>");
TheCodeKing
  • 19,064
  • 3
  • 47
  • 70
0

A link is a link. It can't influence how the browser will handle the content (and nor can anything else in the document)

If you want the browser to download something it would normally render (either natively or with a plugin) then you need to set a Content-Disposition header on the HTTP response.

See this example of how to do it with Apache for PDF files and adapt as per your own requirements.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Except that HTML, The Living Standard has a [`download`](http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#attr-hyperlink-download) attribute for this very purpose. Very new, not implemented anywhere yet I think, and not in the W3C HTML5 draft either. – Alohci Sep 03 '11 at 00:24