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 8418963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:28:32+00:00 2026-06-10T02:28:32+00:00

I’m using Service Stack for a simple web application. In this app i need

  • 0

I’m using Service Stack for a simple web application.

In this app i need to “export” some content to Excel.. So this is the approach I took:

  1. I get the HTML content of a table with jQuery a get the HTML content
    of a table, and send to the service.
  2. The Service write the content to a file (with some CSS)
  3. Using the same service, but with a GET method, I read the file and
    make the download with ContentType:"application/vnd.ms-excel"

I used this approach without Service Stack in other times, and worked well.. The XLS file had the right content and some colors.

Now, when I get the file using GET method (i.e., visiting the url with the browser), the file contents are bad.

ServiceStack let download with some formats: html, csv, jsv, json, xml.

The html format shows up a default report page, the only format that works a little is jsv.

My question is: how can I download the file like plain html file?

Some code:

public class ExcelService : RestServiceBase<Excel>
{   
    public override object OnGet (Excel request)
    {
        string file = request.nombre;
        //Response.Clear();
        HttpResult res = new HttpResult();
        res.Headers[HttpHeaders.ContentType] = "application/vnd.ms-excel";
        res.Headers[HttpHeaders.ContentDisposition] = "attachment; filename="+file+".xls";
        string archivo = System.IO.File.ReadAllText("tmp/"+file+".html");
        res.Response = archivo;
        return res;
    }
}

Thanks in advance

  • 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-10T02:28:34+00:00Added an answer on June 10, 2026 at 2:28 am

    The HttpResult Constructor in ServiceStack as an overload that supports file downloads, e.g:

    return new HttpResult(new FileInfo("tmp/"+file+".html"), 
        asAttachment: true, 
        contentType: "application/vnd.ms-excel");
    

    Which will set the ContentDisposition HTTP headers required for file downloading.

    Creating your own Http Result

    For more fine-grained control of the HttpOutput you can also create your own Result class. Here is an example of downloading an Excel spreadsheet taken from the customized responses in ServiceStack question:

    public class ExcelFileResult : IHasOptions, IStreamWriterAsync
    {
        private readonly Stream _responseStream;
        public IDictionary<string, string> Options { get; private set; }
    
        public ExcelFileResult(Stream responseStream)
        {
            _responseStream = responseStream;
    
            Options = new Dictionary<string, string> {
                 {"Content-Type", "application/octet-stream"},
                 {"Content-Disposition", ""attachment; filename=\"report.xls\";"}
             };
        }
    
        public async Task WriteToAsync(Stream responseStream, CancellationToken token = default)
        {
            if (_responseStream == null) 
                return;
    
            await _responseStream.CopyToAsync(responseStream, token);
            await responseStream.FlushAsync(token);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker

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.