Most times I read book online, where downloads has been restricted. You as a reader can only be able to navigate through the pages of the book. As a beginner programmer I have been trying to do application”Online Library” where the reader can only navigate as well; and not download. I tried with the codes below, but I ended up downloading the book (pdf). Please greatest programmers, I need your help here. Here is the vb.net code, which can only download the book below. Please even if you can put me through with C# or Vb; no problem.

Dim bytFile As Byte() = CType(booktable.Rows(0).Item("Schbook"), Byte())
                Dim strExtenstion As String = "extension of retrieved file"
                Response.Clear()
                Response.Buffer = True

                If (strExtenstion = ".doc" Or strExtenstion = ".docx") Then

                    Response.ContentType = "application/vnd.ms-word"
                    Response.AddHeader("content-disposition", "attachment;filename=Tr.doc")

                ElseIf (strExtenstion = ".xls" Or strExtenstion = ".xlsx") Then

                    Response.ContentType = "application/vnd.ms-excel"
                    Response.AddHeader("content-disposition", "attachment;filename=Tr.xls")

                ElseIf (strExtenstion = ".pdf") Then

                    Response.ContentType = "application/pdf"
                    Response.AddHeader("content-disposition", "attachment;filename=Tr.pdf")

                End If
                Response.Charset = ""
                Response.Cache.SetCacheability(HttpCacheability.NoCache)

                Response.BinaryWrite(bytFile)

                Response.End()


            End Using
        Catch ex As ApplicationException
            MessageBox.Show("Book ID  not supplied properly! ")
        End Try

    End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.