Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > ASP.NET > ASP.NET Upload File > ASP.NET Upload file & BLOB Image Binary



Clound SSD Virtual Server

ASP.NET Upload file & BLOB Image Binary

ASP.NET Upload file & BLOB Binary บทความ ASP.NET Framework การใช้ ASP.NET ทำการ Upload ไฟล์รูปภาพ ลงในฐานข้อมูล Column หรือ Fields ของ Database โดยเก็บข้อมูลไฟล์ ในรูปแบบของ Binary Data ผ่าน Data Type Image ,Binary หรือ BLOB

Language Code : VB.NET || C#

Framework : 2,3,4

Default.aspx.vb

Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        Me.pnlForm.Visible = False

        If Me.fUpload.HasFile = False Or Me.txtName.Text = "" Then
            Me.lblStatus.Text = "Please input Name and Chooes File."
        Else

            '*** Read Binary Data ***'
            Dim imbByte(fUpload.PostedFile.InputStream.Length) As Byte
            fUpload.PostedFile.InputStream.Read(imbByte, 0, imbByte.Length)

            '*** MimeType ***'
            Dim ExtType As String = System.IO.Path.GetExtension(fUpload.PostedFile.FileName).ToLower()
            Dim strMIME As String = Nothing
            Select Case ExtType
                Case ".gif"
                    strMIME = "image/gif"
                Case ".jpg", ".jpeg", ".jpe"
                    strMIME = "image/jpeg"
                Case ".png"
                    strMIME = "image/png"
                Case Else
                    Me.lblStatus.Text = "Invalid file type."
                    Exit Sub
            End Select

            '*** Insert to Database ***'
            Dim objConn As New SqlConnection
            Dim strConnString, strSQL As String

            strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"

            strSQL = "INSERT INTO files (Name,FilesName,FilesType) " & _
            " VALUES " & _
            " (@sName,@sFilesName,@sFilesType)"
            objConn.ConnectionString = strConnString
            objConn.Open()

            Dim objCmd As New SqlCommand(strSQL, objConn)
            objCmd.Parameters.AddWithValue("@sName", Me.txtName.Text)
            objCmd.Parameters.AddWithValue("@sFilesName", imbByte)
            objCmd.Parameters.AddWithValue("@sFilesType", strMIME)
            objCmd.ExecuteNonQuery()

            objConn.Close()
            objConn = Nothing

            Me.lblStatus.Text = "File Upload Successfully. Click <a href='ListPicture.aspx'>here</a> to view."
        End If
    End Sub

End Class


อ่านเต็มรูปแบบได้ที่

Go to : ASP.NET Upload file BLOB and Binary Data การอัพโหลดไฟล์ไบนารี่ด้วย ASP.NET


บทความอื่น ๆ เกี่ยวกับการ Upload โดยใช้ BLOB Binary

Go to : ASP.NET Access BLOB Binary Data and Parameterized Query
Go to : ASP.NET MySQL BLOB Binary Data and Parameterized Query
Go to : ASP.NET SQL Server BLOB Binary Data and Parameterized Query
Go to : ASP.NET Oracle BLOB Binary Data and Parameterized Query






   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2011-05-27 14:08:06 / 2011-06-03 06:32:11
  Download : No files
 Sponsored Links / Related

 
ASP.NET Upload file (HTMLInputFile)
Rating :

 
ASP.NET Upload file (HTMLInputFile - runat="server")
Rating :

 
ASP.NET Upload file (HTMLInputFile - Multiple upload) P.1
Rating :

 
ASP.NET Upload file (HTMLInputFile - Multiple upload) P.2
Rating :

 
ASP.NET Upload file (FileUpload Control)
Rating :

 
ASP.NET Upload & Multiple-FindControl
Rating :

 
ASP.NET Upload & Create Control - FindControl
Rating :

 
ASP.NET Upload file to Database
Rating :

 
ASP.NET Limit Max Size Upload file
Rating :

 
ASP.NET Restrict the types of files (extension)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่