Click here to Skip to main content
12,549,345 members (46,168 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


14 bookmarked

File Upload and Download in ASP.NET

, 5 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
ASP.NET sample code for uploading and downloading files
There are lots of situation, Where we have to use file uploader in our project. But beginners don’t get proper code for Uploading and Downloading File. Using this code they can do it:

File Upload Code

string FilePath = "";
string[] a = new string[1];
string fileName = "";
string FullName = "";
if (FileUploader.FileName.Length > 0)
     a = FileUploader.FileName.Split('.');
     fileName = Convert.ToString(System.DateTime.Now.Ticks) + "." + a.GetValue(1).ToString();
     FilePath = Server.MapPath(@"~\SavedFolder");
     Fup1.SaveAs(FilePath + @"\" + fileName);
     FullName = FilePath + @"\" + fileName;
     // Database Saved Code

File Download Code

string filename = "filename from Database";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
string aaa = Server.MapPath("~/SavedFolder/" + filename);
Response.TransmitFile(Server.MapPath("~/SavedFolder/" + filename));


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


About the Author

Software Developer India
India India
Total DotNet/Programming Solution

I am Prasanta Banerjee. I am an Asp.Net Developer. My site:
If any body wants to prepare for interview is the good site.

You may also be interested in...

Comments and Discussions

BugDownload code not working Pin
narenderkumardhull29-Jan-14 21:57
membernarenderkumardhull29-Jan-14 21:57 
Questionin case of .xls and in firefox this is not working Pin
V1CT0R.15-Dec-13 23:05
memberV1CT0R.15-Dec-13 23:05 
Questionhow to download uploaded file Pin
manikantaer12-Jul-12 18:35
membermanikantaer12-Jul-12 18:35 
Generalcan this code be used to download any kind of file Pin
ashishmaniyar13-Nov-11 19:06
memberashishmaniyar13-Nov-11 19:06 
Generalchange code line Pin
zSegundo2-May-11 13:29
memberzSegundo2-May-11 13:29 
Generalur code for file download Pin
kanvmukti26-Apr-11 19:47
memberkanvmukti26-Apr-11 19:47 
Answer code for file download from server Pin
Member 1019759928-Aug-13 5:29
memberMember 1019759928-Aug-13 5:29 
GeneralWhat happens if... Pin
Henry Minute24-Apr-11 11:31
mvpHenry Minute24-Apr-11 11:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 5 May 2011
Article Copyright 2011 by Prasanta_Prince
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid