What is wrong with this c# method?-Collection of common programming errors
Just my $0.10, it’s pretty clear that the content header is being returned here, so if we don’t recognize the file extension, rather than throw exceptions or invalid MIME header information (e.g., “unknown”), we should return the file to the browser as an octect stream, like this:
public string ReturnExtension(string fileExtension)
{
switch (fileExtension)
{
case ".doc":
case ".docx":
return "application/ms-word";
default:
return "application/octet-stream";
}
}
This way we can accommodate scenarios where 5 years down the road, M$ releases MS-Word v30.1, and the extension becomes “.docz”, the system will not throw exceptions, but invoke MS-Word (more) gracefully, albeit not using the IE-enhanced behavior that “application/ms-word” will.