C# – How to download a file through the application

c

Hai Guys.,

Im doing an Application titled Online Education. In my application i have to enable the trainees to download the pdf tutorials that i've been already stored in database.How can I do this process using C#.Net..,

Thanks in advance for those who answer this question….,

Shankar.

Best Answer

So you are already putting your file in DB?

To allow users download file you should use Response.BinaryWrite. You will also need to send some special headers to user.

All in all the code looks like this:

  Response.ContentType = "Application/pdf";
  Response.AppendHeader( "content-disposition", "attachment; filename=" + name );
  Response.BinaryWrite(data);
  Response.End();