0

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
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jfarrugia
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.