O'Reilly logo

Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API by Ragini Kumbhat Bhandari, Nishanth Nair

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

An Image/PDF file as response

It's a common requirement in most of the applications to retrieve a PDF or image file as response. It's quite easy to implement this scenario in Web API by writing a couple of lines of code in your action method to override the default media type of the response determined by Content Negotiation.

Let's open up the ValuesController.cs file, and add one more action method called GetImage(), which will return an image file in the Content folder of the service as shown:

public HttpResponseMessage GetImage()
{
    byte[] bytes = System.IO.File.ReadAllBytes(
        HttpContext.Current.Server
        .MapPath("~/Content/Kendo.png"));
    var result = new HttpResponseMessage(HttpStatusCode.OK);
    result.Content = new ByteArrayContent(bytes);
    result.Content.Headers.ContentType ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required