Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
1.25/5 (3 votes)
See more:
Hi All,

I have a web application and in that I have a folder named as Download and I have a docx file as instructions.docx.
In aspx page I took a button and onlick button I want to download instructions.docx from its path means "~/Download/instructions.docx" .I tried my best but I am unable to do it.

Please help me in sorting out my problem.

Thanking You.
Mohd. Wasif
Posted
Updated 9-Aug-16 21:20pm

Use this code on Button click
Response.Redirect("~/Download/instructions.docx");


It is very simple.On clicking this it will display the Options, based on this you can save it by selceting your Location.
 
Share this answer
 
If you want to force save as dialog then see the following

http://aspalliance.com/259[^]

http://www.west-wind.com/weblog/posts/76293.aspx[^]
 
Share this answer
 
Hello Mohd.Wasif

You can simply do it with the help of
Response.Redirect("~/Download/instructions.docx");


It is working perfectly.
When you click on the Button.. The file Download box will appear having the option of Open, Save and Cancel..


Hope this will help you.

Regards
Shweta
:rose:
 
Share this answer
 
Comments
Sandeep Mewara 14-Feb-11 7:59am    
Good answer. 5!
ShwetaSaxena 15-Feb-11 3:42am    
@Sandeep Thanks
ridoy 8-Aug-16 6:44am    
a 5.
write the following code on button click event

Response.Redirect("~/Download/instructions.docx");
 
Share this answer
 
v2
Comments
Sandeep Mewara 14-Feb-11 7:59am    
Yep!
C#
Dim downloadFile As New System.IO.FileInfo(outputFileName)
          If downloadFile.Exists Then
              context.Response.Clear()
              context.Response.ContentType = "application/pdf"
              context.Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", downloadFile.Name))
              context.Response.AddHeader("Content-Length", downloadFile.Length.ToString())
              context.Response.TransmitFile(downloadFile.FullName)
              context.Response.Flush()
          Else
              Throw New Exception("File not found")
          End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900