It's been a while since I've been here. I've been working on an ASP project where the attachment is stored to DB. I'm trying to get the bytes stored in the table to a file.I was able to make the file, however, I couldn't get the bytes from the table.This is the code that enters the file to the table: \[code\]'Saves the upload file data to database for the using Request_ID after the request has been createdPrivate Sub SaveFileToDB(ByVal Request_ID As Integer) Dim strFileName, strFileExt As String Dim intFileSize As Integer Dim strSQL As String Dim cnToDb As New SqlConnection Dim cmdSQL As New SqlCommand strFileName = FileUploadReqDtl.FileName strFileExt = strFileName.Substring(strFileName.IndexOf(".") + 1) intFileSize = FileUploadReqDtl.PostedFile.ContentLength() Dim theDataSize As Byte() = New Byte(FileUploadReqDtl.PostedFile.ContentLength - 1) {} Dim uploadedFile As HttpPostedFile = FileUploadReqDtl.PostedFile Dim theData = http://stackoverflow.com/questions/13784720/uploadedFile.InputStream.Read(theDataSize, 0, CInt(FileUploadReqDtl.PostedFile.ContentLength)) strSQL ="" strSQL = "INSERT INTO tblFileUploadData (Report_ID, FileName, FileExtension, Data) " _ & "VALUES (" & Request_ID & ", '" & strFileName & "', '" & strFileExt & "', " & theData & ")" cnToDb.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\RptTrackerDB.mdf;Integrated Security=True;User Instance=True" cnToDb.Open() cmdSQL.CommandText = strSQL cmdSQL.Connection = cnToDb cmdSQL.ExecuteNonQuery()End Sub\[/code\]I was able to create a link on a page that goes to another ASP page and tries to make the file downloadable. I know that the SQL is working properly to get the records from the table, however, I'm not able to get the bytes properly: \[code\] dr = cmdSQL.ExecuteReader If (dr.HasRows = True) Then While dr.Read() ' We are casting the value returned by the datareader to the byte[] data type. result = CType(dr.GetValue(0), Byte()) strFileName = dr.GetString(1) Debug.Write("strFileName: " & strFileName & vbCrLf) End While End If dr.Close() cnToDb.Close() ShowFile(strFileName, result, MimeType) Catch ex As Exception MsgBox("Uh oh, I couldn't get the attachment!") Debug.Write("Uh oh, I couldn't get the attachment!") Debug.Write(ex.Message & " - " & ex.StackTrace & vbCrLf & vbCrLf) result = Nothing End Try\[/code\]This is the ShowFile function which finally "creates the file" with the bytes from the database: \[code\]Protected Sub ShowFile(ByVal strFileName As String, ByVal byteFileData() As Byte, ByVal MimeType As String) ' ' Downloads the selected file and displays it in the picture box. ' ' ' Finds the unique id of the file. ' Dim fileData() As Byte fileData = http://stackoverflow.com/questions/13784720/byteFileData Response.Clear() Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName) Response.ContentType = MimeType Response.BinaryWrite(fileData) Response.End() Response.Flush()End Sub\[/code\]The exception I'm hitting that I'm having issues with is: \[quote\] SQL: SELECT Data, FileName FROM tblFileUploadData WHERE Report_ID = 116 strFileName: TheAwesomeAttachment.txt A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll Uh oh, I couldn't get the attachment!Thread was being aborted. - at System.Threading.Thread.AbortInternal() at System.Threading.Thread.Abort(Object stateInfo) at System.Web.HttpResponse.End() at WebApplication3.WebForm2.ShowFile(String strFileName, Byte[] byteFileData, String MimeType) in C:\Users\Junaid\documents\visual studio 2010\Projects\WebApplication3\WebApplication3\Attachment.aspx.vb:line 81 at WebApplication3.WebForm2.getAttachment(Int32 RequestID, String MimeType) in C:\Users\Junaid\documents\visual studio 2010\Projects\WebApplication3\WebApplication3\Attachment.aspx.vb:line 56 A first chance exception of type 'System.Threading.ThreadAbortException' occurred in WebApplication3.DLL An exception of type 'System.Threading.ThreadAbortException' occurred in WebApplication3.DLL but was not handled in user code The thread '' (0x728) has exited with code 0 (0x0). The program '[13512] WebDev.WebServer40.EXE: Managed (v4.0.30319)' has exited with code 0 (0x0). The program '[13512] WebDev.WebServer40.EXE: Program Trace' has exited with code 0 (0x0).\[/quote\]