Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to upload and download a file using only a linkbutton on c# and asp.net thanks


What I have tried:

im new on the programming and i need some help to download only a file i already done uploading some file but i cant download using a linkbutton
Posted
Updated 27-Sep-17 17:52pm
Comments
Karthik_Mahalingam 25-Sep-17 0:08am    
post your code,
what is the issue
Member 13427032 27-Sep-17 10:57am    
Hello Good Day here's my code to upload the file.

protected void btnUpload_Click(object sender, EventArgs e)
{
string fileName = "";

string uploadPath = WebConfigurationManager.AppSettings["SubPic"].ToString();
if (FileUpload.HasFile)
{
string fileExtension = Path.GetExtension(FileUpload.PostedFile.FileName);
fileName = "Comment-" + Issue.ReportedOn.ToString("yyyy-MM-dd_HH-mm-ss") + fileExtension;
FileUpload.SaveAs(uploadPath + "\\" + System.IO.Path.GetFileName(FileUpload.FileName));
Label1.Text += "Location of the file: " + uploadPath + "\\" + System.IO.Path.GetFileName(FileUpload.FileName);

}
and i dont know how to download the file using the linkbutton.
Thanks for the help
Karthik_Mahalingam 27-Sep-17 23:17pm    
what kind of file it is

Create a hyperlink to your file.
 
Share this answer
 
Quote:
and i dont know how to download the file using the linkbutton.

LinkButton is like a normal button with CSS like an anchor Tag.
try this

protected void LinkButton1_Click(object sender, EventArgs e)
       {
           string filePath = "Your file path from the folder";
           Response.ContentType = ContentType;
           Response.AppendHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(filePath));
           Response.WriteFile(filePath);
           Response.End();
       }
 
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