Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Upload and Download File using ASP.Net

Upload And Download File Using ASP.Net

Tags | how to Upload and download file in asp.net, upload and download file in asp.net, code to upload and download files in asp.net, source code for file upload and download in asp.net.

How to upload and download file in asp.net

Uploading and downloading files are the most common methods for any website or asp.net web application. The FileUpload web server control allows you to provide users with a way to send a file from their computer to the server.

Note: The maximum size file that can be uploaded depends on the value of the MaxRequestLength configuration setting. If users attempt to upload a file that is larger than the maximum, the upload fails.

Code to upload and download files in asp.net

In this C# ASP.Net tutorial I will demonstrates how to upload and download files from folder in asp.net using c#. Find the below source code for file upload and download in asp.net :-



    Save/Upload files in folder and download files from folder system.

Upload and Download file in asp.net using c#

Upload Download
using System; using System.IO; public partial class _Default : System.Web.UI.Page { string filename = string.Empty; protected void Page_Load(object sender, EventArgs e) { } //To upload file protected void OnLnkUpload_Click(object sender, EventArgs e) { filename = Path.GetFileName(fileUpload1.PostedFile.FileName); fileUpload1.SaveAs(Server.MapPath("Files/" + filename)); lblFilename.Text = "Files/" + fileUpload1.FileName; lblMessage.Text = "File uploaded sucessfully to the folder: -" + " Files/" + fileUpload1.FileName; } // To download uplaoded file protected void OnLnkDownload_Click(object sender, EventArgs e) { if (lblFilename.Text != string.Empty) { if (lblFilename.Text.EndsWith(".txt")) { Response.ContentType = "application/txt"; } else if (lblFilename.Text.EndsWith(".pdf")) { Response.ContentType = "application/pdf"; } else if (lblFilename.Text.EndsWith(".docx")) { Response.ContentType = "application/docx"; } else { Response.ContentType = "image/jpg"; } string filePath = lblFilename.Text; Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\""); Response.TransmitFile(Server.MapPath(filePath)); Response.End(); } } }

Download ASP Net C# Source Code

References | https://msdn.microsoft.com/en-us/library/ms227669.aspx

The following example shows how to work with an uploaded file. The code checks the file name extension of the uploaded file against a hard-coded list of allowed file name extensions and rejects all other types of files.

Did you find this post useful? I hope you liked this article. Please share with me your valuable suggestions and feedback.

The post Upload and Download File using ASP.Net appeared first on Dot Net Tutorial, C# Tutorial, Google Maps API JavaScript, Dot Net Tricks.



This post first appeared on Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps API Developer, please read the originial post: here

Share the post

Upload and Download File using ASP.Net

×

Subscribe to Asp Dot Net Tricks And Tips, Dot Net Coding Tips, Google Maps Api Developer

Get updates delivered right to your inbox!

Thank you for your subscription

×