Thursday 15 November 2012

Download a file Programmatically C#


Download a file Programmatically C#


Use the following Code-Snippet to Download a particular file-type Programmatically:


FileStream fs; 
object strPath = "C:\\My External\\File Path\\"; 
string strFileName = "7f0873f1.mp3"; 

// Check Validation Here
if (true) 
{ 
 fs = File.Open(strPath + strFileName, FileMode.Open); 
 byte[] bytBytes = new byte[fs.Length]; 
 fs.Read(bytBytes, 0, Convert.ToInt32(fs.Length)); 
 fs.Close(); 
 Response.AddHeader("Content-disposition", "attachment; filename=" + strFileName); 
 Response.ContentType = "application/octet-stream"; 
 Response.BinaryWrite(bytBytes); 
 Response.End(); 
} 
else 
{ 
 // Error
}

1 comment:

  1. This is an excellent component for verifying email addresses:
    http://www.kellermansoftware.com/p-37-net-email-validation.aspx

    ReplyDelete

Thank You for Your Comments. We will get back to you soon.

back to top