<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" />
<hr />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="File Name" />
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="lnkView" runat="server" Text="View" OnClick="View" CommandArgument='<%# Eval("Id") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<hr />
<div>
<asp:Literal ID="ltEmbed" runat="server" />
</div>
</div>
<pre lang="vb"><pre lang="vb">
Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports Framework
Public Class dap_trn_documentupload
Inherits System.Web.UI.Page
Dim objdbconn As New dbconn
Dim msSQL As String
Dim ds_users As New DataSet
Dim mnResult As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGrid()
End If
End Sub
Private Sub BindGrid()
objdbconn.OpenConn()
msSQL = "select Id, Name from tblFiles"
ds_users = objdbconn.GetDataSet(msSQL, "tblFiles")
GridView1.DataSource = ds_users
GridView1.DataMember = "tblFiles"
GridView1.DataBind()
objdbconn.CloseConn()
End Sub
Protected Sub Upload(sender As Object, e As EventArgs)
Dim filename As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
Dim contentType As String = FileUpload1.PostedFile.ContentType
Using fs As Stream = FileUpload1.PostedFile.InputStream
Using br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CType(fs.Length, Long))
objdbconn.OpenConn()
msSQL = ""
msSQL &= "insert into tblFiles (Name,ContentType) "
msSQL &= " values('" & filename & "','" & contentType & "')"
mnResult = objdbconn.ExecuteNonQuerySQL(msSQL)
objdbconn.CloseConn()
End Using
End Using
Response.Redirect(Request.Url.AbsoluteUri)
End Sub
End Class
DB
DROP TABLE IF EXISTS `tabtree_new`.`tblfiles`;
CREATE TABLE `tabtree_new`.`tblfiles` (
`Id` int(10) unsigned NOT NULL auto_increment,
`Name` varchar(45) NOT NULL,
`ContentType` varchar(200) NOT NULL,
`Data` varbinary(5000) default NULL,
PRIMARY KEY USING BTREE (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
What I have tried:
Protected Sub View(ByVal sender As Object, ByVal e As EventArgs)
Dim id As Integer = Integer.Parse(TryCast(sender, LinkButton).CommandArgument)
Dim embed As String = "<object data=""{0}{1}"" type=""application/pdf"" width=""500px"" height=""600px"">"
embed += "If you are unable to view file, you can download from <a href = ""{0}{1}&download=1"">here</a>"
embed += " or download <a target = ""_blank"" href = ""http://get.adobe.com/reader/"">Adobe PDF Reader</a> to view the file."
embed += "</object>"
ltEmbed.Text = String.Format(embed, ResolveUrl("~/ems_dailyprocess/pdf-sample.pdf"), id)
End Sub
what shoul i hav mistake in this code i dont no
if the file upload and value should be set on grid is sucessfully when i click the particular Pdf i need to view that particular File what i should writen can any 1 help me to give the idea about that code its really help me for my knowledge