I wanted to use this code to display both pdf and word files in the browser without downloading it to the computer please help
Protected Sub lnkDownload_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim lnkbtn As LinkButton = TryCast(sender, LinkButton)
Dim gvrow As GridViewRow = TryCast(lnkbtn.NamingContainer, GridViewRow)
Dim fileid As Integer = Convert.ToInt32(GridView1.DataKeys(gvrow.RowIndex).Value.ToString())
' Dim name As String, type As String
Using con As New SqlConnection(strCon)
Using cmd As New SqlCommand()
cmd.CommandText = "select Name, ContentType, Data,years,dateadded from tblFiles where Id=@Id"
cmd.Parameters.AddWithValue("@id", fileid)
cmd.Connection = con
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read() Then
Response.ContentType = dr("ContentType").ToString()
Response.AddHeader("Content-Disposition", "attachment;filename=""" & Convert.ToString(dr("Name")) & """")
Response.BinaryWrite(DirectCast(dr("Data"), Byte()))
Response.[End]()
End If
End Using
End Using
End Sub
The challenge i have with these two examples is that the pdf and word files get brocked so i wanted to open the pdf files using code instead of this
<a class="view" href="javascript:;" rel='<%# Eval("Id") %>'>View Word</a>