User Id :    Password :      New Member   Forgot Password  
 
File Downloading Code in C#
Description Generally we provide the facility to download certain file on some event like button click. So here I am providing simple c#.net code to do this.   No. of Views     1324
  Rating     5
Author Sumit Gupta   Posted On     15 Apr 2011
Tags ASP.NET,C#    

Sample Code   Download Code

using System.IO;

 FileInfo finfo = new FileInfo(Server.MapPath("~/YourFolderName/YourFileName"));
        
        if (finfo.Exists)
        {
            Response.ClearContent();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + finfo.Name);
            Response.AddHeader("Content-Length", finfo.Length.ToString());
            Response.ContentType = "application//octet-stream";
            Response.TransmitFile(finfo.FullName);
            Response.End();
        }

 

About Author

About Author I am Sumit Gupta working in 3 Pillar Global Pvt. Ltd as Module Lead. I have 7+ year of experience in .Net technologies. I love to explore new technologies and write technical article. Sumit Gupta
No Photo
 
Country India
Company 3 Pillar Global Pvt. Ltd.
Home Page http://www.facebook.com/sumitgupta1225

Rate this article

Rating options from poor, fair, good, very good to excelent.  
 

Comments

   
Write your comment here.
Comment
Verification Code