hello
i have application is devlopped aspnet and c_charp i have add the form to aupload and downlod file
hello
i have application is devlopped aspnet and c_charp i have add the form to aupload and downlod file
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhishek YadavRank #217 · 11.3K reputationPosted Aug 26, 2023, 12:22 AM EDT
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { if (Request.Files.Count > 0) { HttpPostedFile file = Request.Files[0]; if (file.ContentLength > 0) { string fileName = Path.GetFileName(file.FileName); file.SaveAs(Server.MapPath("~/Uploads/" + fileName)); // Save the file to a directory on the server } } } }protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string[] fileNames = Directory.GetFiles(Server.MapPath("~/Uploads/")); foreach (string fileName in fileNames) { string fileUrl = "~/Uploads/" + Path.GetFileName(fileName); HyperLink link = new HyperLink(); link.Text = Path.GetFileName(fileName); link.NavigateUrl = fileUrl; // You can also create a download button instead of a hyperlink // using the ASP.NET Button control. pnlDownloads.Controls.Add(link); pnlDownloads.Controls.Add(new LiteralControl(" ")); } } }Ensure that you have a folder named "Uploads" in your project's root directory to save the uploaded files. Also, make sure the appropriate write permissions are set for this folder.
This is a basic implementation, and you can further enhance it by adding validations, checking file extensions, handling duplicate file names, and providing additional features depending on your requirements.