Published on: 21 February, 2016

How to trigger a download file in c# MVC controller

Posted by andy | 677 views 0 likes 0 favourites 0 comments
Tumblr Digg Google Plus

you want to know how you can easily trigger a popup download in MVC controller rather than using a href link to open into a new window?

Below is the simple script on how you can do it.

public FileContentResult Download(long listingID) {
	var document = new FileInfo(Server.MapPath("~/sample.pdf"));
	if (document != null) {
		Response.AppendHeader("Content-Disposition", "FileName=sample.pdf");
		return File(System.IO.File.ReadAllBytes(filepath), "application/octet-stream");
	return null;

There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.
Related Articles
Published on: 28 October, 2016

In this tutorial you will learn how easily you can implement a simple checkout express using C# MVC Web API. We will create a really simple shopping cart where customers can add and delete their cart items before proceed to payment.