ServiceStack – Force file download

Making a call to ServiceStack to force a file to download.

C# Service (ServiceStack)

Using a normal ServiceStack service. A GET method is used to allow the following JavaScript call to easily call it. This will cause the browser to deliver the file itself.

The example is simplified in that the response object writes a string. A binary stream for example could also also be written.

jQuery Async Call

Remember to return false from the click function to prevent the page from reloading (assuming #forceDownload is a button or link).