Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8464465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:45:15+00:00 2026-06-10T14:45:15+00:00

I have a WebAPI controller that need to download some files depending of the

  • 0

I have a WebAPI controller that need to download some files depending of the request, but when it comes to plain text files it doesnt give me the browser’s download requisition. It only give me the plain text response like it was JSON (in my case, it’s a JSONP WebAPI).

I’ve checked others Q&A from stack (and other sites), but I still got nothing:

  • Is there a way to force ASP.NET Web API to return plain text?

  • Returning binary file from controller in ASP.NET Web API

  • ASP .Net Web API downloading images as binary

Here it goes my current code:

var httpResponse = new HttpResponseMessage(HttpStatusCode.OK);
httpResponse.Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes(content)));
httpResponse.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
httpResponse.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
httpResponse.Content.Headers.ContentDisposition.FileName = "speedcam.txt";
return httpResponse;

And this is Chrome’s response:

Cache-Control:no-cache

Content-Disposition:attachment; filename=speedcam.txt

Content-Length:17462

Content-Type:application/octet-stream

Date:Mon, 27 Aug 2012 04:53:23 GMT

Expires:-1

Pragma:no-cache

Server:Microsoft-IIS/8.0

X-AspNet-Version:4.0.30319

X-Powered-By:ASP.NET

X-SourceFiles:=?UTF-8?B?TTpcVHJhYmFsaG9cTWFwYVJhZGFyXE1hcGFSYWRhci5XZWJBUEk0XEV4cG9ydGE=?

Seems OK, but the whole file text is in the Chrome Dev Tools "Response Tab"..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:45:17+00:00Added an answer on June 10, 2026 at 2:45 pm

    After a lot of research and text, I found out the hard way that an AJAX request CANNOT download files. Thanks to these two answers:

    JavaScript/jQuery to download file via POST with JSON data

    Ajax File Download using Jquery, PHP

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET WebApi application that has some controller methods that expect certain
I have a desktop webapi server that I want to expose to clients through
I have a Asp.net WebAPI service that is hosted on AppHarbor which throws 404
I have a layered web application that I built with ASP.NET MVC 4, WebAPI
I recently switched one of my static html files to a Spring controller that
I have an ASP.NET WebApi project that utilizes Entity Framework 4.1. I am attempting
I receive only on certain files an error when uploading to a webapi controller.
I have heard a few people make the comment that the default controller/provider for
I have some data Foo that I want to pass from the browser to
Here's the setup: I have some MVC Controllers that are intended to be consumed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.