Click here to Skip to main content
15,848,157 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
string url = ResolveUrl(ConfigurationManager.AppSettings["ResourcesFilePath"] + filename);
if (!RequiresRegistration || !DownloadRegistrationHelper.GetIsRegistrationEnabled())
{
htmlBuilder.AppendLine(string.Format(@"{1}", url, linkText));
}

above code renders in following manner

An Automated Solid Phase Extraction (SPE) Method for the Determination of Chloramphenicol in Honey

but while download file extension is not downloading in some machines (both in chrome & fiefox)

file extension should come in all browsers, any alternatives ? pls advise
Posted
Comments
Sergey Alexandrovich Kryukov 20-Oct-15 11:37am    
What does it mean, "download file extension"? In fact, there is no such entity as "extension", this is no more than metaphor based on the notion of obsolete file systems where it was something real.
—SA

1 solution

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[^]:
C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900