The Daily WTF
Jeremy found this VB.Net code. It has a simple job: return a file back to the client, but with a twist: they don’t know what the correct file extension is. So this was their solution for that problem:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Application(“PointsWhere”) = “DEV” Then Dim strFile As String strFile = Application(“UploadPODs”).ToString.Trim & Session(“PODClaim”) & “.pdf” If System.IO.File.Exists(strFile) Then Response.ContentType = “Application/pdf” Else strFile = Application(“UploadPODs”).ToString.Trim & Session(“PODClaim”) & “.jpeg” If System.IO.File.Exists(strFile) Then Response.ContentType = “image/jpeg” Else strFile = Application(“UploadPODs”).ToString.Trim & Session(“PODClaim”) & “.jpg” If System.IO.File.Exists(strFile) Then Response.ContentType = “image/jpeg” Else strFile = Application(“UploadPODs”).ToString.Trim & Session(“PODClaim”) & “.gif” If System.IO.File.Exists(strFile) Then Response.ContentType = “image/gif” Else strFile = Application(“UploadPODs”).ToString.Trim & Session(“PODClaim”) & “.bmp” If System.IO.File.Exists(strFile) Then Response.ContentType = “image/bmp” Else strFile = Application(“UploadPODs”).ToString.Trim & Session(“PODClaim”) & “.png” If System.IO.File.Exists(strFile) Then Response.ContentType = “image/png” Else strFile = Application(“UploadPODs”).ToString.Trim & Session(“PODClaim”) & “.tiff”
To read the full article click on the 'post' link at the top.