Friday, July 17, 2009

Download file from server using Response.TransmitFile

hi.
we can user Response.TransmitFile to Allow users to download file.
here is the code to download file.You have to change Response.ContentType attribute as per type of your content.

Here is the sample code.

if (File.Exists(FilePath))
{
Response.ContentType = "image/jpeg"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + "FileName.jpeg"); Response.TransmitFile(FilePath);
Response.End();
}

Thanks.