If you want to force a file to be downloaded, rather than opening in the browser, you have a couple of options.
Recent versions of both Chrome and Firefox
support the download
attribute[
^]:
htmlBuilder.AppendLine(string.Format(@"<a href=""{0}"" download=""{1}"">{2}</a>", url, filename, linkText));
If that doesn't work, then you'll need to serve the file with a custom
Content-Disposition
header.
This answer on StackOverflow[
^] explains how to set the header in IIS.
In some cases, IE tries to be "helpful", and decides to open the file anyway. You can avoid that with two additional headers:
X-Content-Type-Options: nosniff
and
X-Download-Options: noopen
.