code for downloading a file

  • Thread starter Thread starter CreativeMind
  • Start date Start date
C

CreativeMind

hi, I am facing problem in download hyperlink..plz give me the
solution.
in codebehind,
private void repDocuments_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
System.Web.UI.WebControls.HyperLink myLink =
(System.Web.UI.WebControls.HyperLink)repDocuments.Items.FindControl("LnkDownLoad");
and in aspx page,
<TD align="left" valign="top" class="GridCell"><a id="LnkDownLoad"
href='../PropertyDocuments/<%#DataBinder.Eval(Container,
"DataItem.PhysicalFileName")%>' class="recordLink LnkAppear">
Download</a></TD>
....now when i click on hyperlink 'download', i see the the file in
browser window but i want the download dialog , how can i do that??
thx
 
hi, I am facing problem in download hyperlink..plz give me the
solution.
in codebehind,
 private void repDocuments_ItemDataBound(object sender,
System.Web.UI.WebControls.RepeaterItemEventArgs e)
 System.Web.UI.WebControls.HyperLink myLink =
(System.Web.UI.WebControls.HyperLink)repDocuments.Items.FindControl("Lnk DownLoad");
and in aspx page,
<TD align="left" valign="top" class="GridCell"><a id="LnkDownLoad"
href='../PropertyDocuments/<%#DataBinder.Eval(Container,
"DataItem.PhysicalFileName")%>' class="recordLink LnkAppear">
Download</a></TD>
...now when i click on hyperlink 'download', i see the the file in
browser window but i want the download dialog , how can i do that??
thx


If you want to have the "Save File As" dialog to be presented to the
client, instead of pointing to the file you have to create a new page
which would send a content of the file to the browser with a flag to
force download

Response.AddHeader("Content-Disposition", "attachment;.....

You can find a lot of tutorials for this, for example,
http://www.aspnetmime.com/tutorials/Sample_AttachmentToBrowser.aspx

Another option is to open the link in the new window, using
target=_blank...
 
Back
Top