Friday, November 16, 2007

Open a file with corresponding Editor

If dsAttachmentData.Tables(0).Rows.Count > 0 Then
Response.Clear()
Dim strFileExt As String() = dsAttachmentData.Tables(0).Rows(0)("ATCHT_FILE_NM").ToString().ToUpper().Trim().Split(".")

If strFileExt(1) = "DOC" Then
Response.ContentType = "application/msword"
Else If strFileExt(1) = "XLS" Then
Response.ContentType = "application/vnd.ms-excel"
ElseIf strFileExt(1) = "PDF" Then
Response.ContentType = "application/pdf"
ElseIf strFileExt(1) = "TXT" Then
Response.ContentType = "text/HTML"
Response.ContentType = "text/plain"
End If
Dim strRecdFileName As String = dsAttachmentData.Tables(0).Rows(0) ("ATCHT_FILE_NM").ToString()
Response.AddHeader("Content-Disposition", String.Format("attachment;filename={0}", strRecdFileName))
Dim fileContent As Byte() = CType(dsAttachmentData.Tables(0).Rows(0)("ATCHT_CNTNT"), Byte())
Response.OutputStream.Write(fileContent, 0, fileContent.Length)
Response.End()
End If



























































No comments: