{"id":5242,"date":"2014-03-30T20:00:13","date_gmt":"2014-03-30T20:00:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/what-is-wrong-with-this-c-method-collection-of-common-programming-errors\/"},"modified":"2014-03-30T20:00:13","modified_gmt":"2014-03-30T20:00:13","slug":"what-is-wrong-with-this-c-method-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/what-is-wrong-with-this-c-method-collection-of-common-programming-errors\/","title":{"rendered":"What is wrong with this c# method?-Collection of common programming errors"},"content":{"rendered":"<p>Just my $0.10, it&#8217;s pretty clear that the content header is being returned here, so if we don&#8217;t recognize the file extension, rather than throw exceptions or invalid MIME header information (e.g., &#8220;unknown&#8221;), we should return the file to the browser as an octect stream, like this:<\/p>\n<pre><code>public string ReturnExtension(string fileExtension)\n{\n    switch (fileExtension)\n    {\n        case \".doc\":\n        case \".docx\":\n            return \"application\/ms-word\";\n        default:\n            return \"application\/octet-stream\";\n    }\n}\n<\/code><\/pre>\n<p>This way we can accommodate scenarios where 5 years down the road, M$ releases MS-Word v30.1, and the extension becomes &#8220;.docz&#8221;, the system will not throw exceptions, but invoke MS-Word (more) gracefully, albeit not using the IE-enhanced behavior that &#8220;application\/ms-word&#8221; will.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just my $0.10, it&#8217;s pretty clear that the content header is being returned here, so if we don&#8217;t recognize the file extension, rather than throw exceptions or invalid MIME header information (e.g., &#8220;unknown&#8221;), we should return the file to the browser as an octect stream, like this: public string ReturnExtension(string fileExtension) { switch (fileExtension) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5242","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5242","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5242"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5242\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5242"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5242"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5242"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}