.NET Programming
--
Questions
--
Followers
Top Experts
Open different content type of files. vb.net
I have the following:
Protected Sub GridViewAttachments_RowCom mand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. GridViewCo mmandEvent Args) Handles GridViewAttachments.RowCom mand
    If e.CommandName = "Browse" Then
      Dim myConnection As New SqlConnection(Configuratio nManager.C onnectionS trings("Co nnectionSt ring").Con nectionStr ing)
      Dim index As Integer = Convert.ToInt32(lblIntervi ewID.Text)
      Try
        Dim ds As New DataSet
        Dim da As SqlClient.SqlDataAdapter
        Dim arrContent As Byte()
        Dim dr As DataRow
        Dim strSql As String
       Â
        strSql = "Select * from [tbl_dotnet_attachments] Where [AttachmentID]='" + e.CommandArgument.ToString () + "'"
        Dim myCommand As New SqlCommand(strSql, myConnection)
        da = New SqlClient.SqlDataAdapter(s trSql, myConnection)
        da.Fill(ds)
        dr = ds.Tables(0).Rows(0)
        arrContent = CType(dr.Item("ImageConten t"), Byte())
        Dim filePath As String = dr.Item("Filename").ToStri ng()
        Dim dotPosition As Integer = filePath.LastIndexOf(".")
        Dim filenameOnly As String = filePath.Substring(dotPosi tion + 1)
        Select Case filenameOnly
          Case "zip"
            Response.ContentType = "application/x-zip-compres sed"
          Case "pdf"
            Response.ContentType = "application/pdf"
          Case "csv"
            Response.ContentType = "application/csv"
          Case "doc"
            Response.ContentType = "application/doc"
          Case "docx"
            Response.ContentType = "application/docx"
          Case "xls"
            Response.ContentType = "application/xls"
          Case "xlsx"
            Response.ContentType = "application/xlsx"
          Case "png"
            Response.ContentType = "application/png"
          Case "gif"
            Response.ContentType = "application/gif"
          Case "jpg"
            Response.ContentType = "application/jpg"
          Case "csv"
            Response.ContentType = "application/csv"
          Case "txt"
            Response.ContentType = "application/txt"
        End Select
        Response.BinaryWrite(arrCo ntent)
        Response.Flush()
        Response.Close()
      Catch ex As Exception
    Â
      End Try
     Â
    End If
  End Sub
it fails when I try to write the binary content.
Protected Sub GridViewAttachments_RowCom
    If e.CommandName = "Browse" Then
      Dim myConnection As New SqlConnection(Configuratio
      Dim index As Integer = Convert.ToInt32(lblIntervi
      Try
        Dim ds As New DataSet
        Dim da As SqlClient.SqlDataAdapter
        Dim arrContent As Byte()
        Dim dr As DataRow
        Dim strSql As String
       Â
        strSql = "Select * from [tbl_dotnet_attachments] Where [AttachmentID]='" + e.CommandArgument.ToString
        Dim myCommand As New SqlCommand(strSql, myConnection)
        da = New SqlClient.SqlDataAdapter(s
        da.Fill(ds)
        dr = ds.Tables(0).Rows(0)
        arrContent = CType(dr.Item("ImageConten
        Dim filePath As String = dr.Item("Filename").ToStri
        Dim dotPosition As Integer = filePath.LastIndexOf(".")
        Dim filenameOnly As String = filePath.Substring(dotPosi
        Select Case filenameOnly
          Case "zip"
            Response.ContentType = "application/x-zip-compres
          Case "pdf"
            Response.ContentType = "application/pdf"
          Case "csv"
            Response.ContentType = "application/csv"
          Case "doc"
            Response.ContentType = "application/doc"
          Case "docx"
            Response.ContentType = "application/docx"
          Case "xls"
            Response.ContentType = "application/xls"
          Case "xlsx"
            Response.ContentType = "application/xlsx"
          Case "png"
            Response.ContentType = "application/png"
          Case "gif"
            Response.ContentType = "application/gif"
          Case "jpg"
            Response.ContentType = "application/jpg"
          Case "csv"
            Response.ContentType = "application/csv"
          Case "txt"
            Response.ContentType = "application/txt"
        End Select
        Response.BinaryWrite(arrCo
        Response.Flush()
        Response.Close()
      Catch ex As Exception
    Â
      End Try
     Â
    End If
  End Sub
it fails when I try to write the binary content.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
i was missing Response.AddHeader("Conten t-disposit ion", "attachment;filename=" &Â strFriendlyName) //Make sure to
it is working.
it is working.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
.NET Programming
--
Questions
--
Followers
Top Experts
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.