palani q

palani q

  • NA
  • 1
  • 0

how to upload zip file into sql db

Mar 4 2009 1:00 AM
i want to upload any file or ZIP/RAR file into to database using vb.net and also i want download files from db..now i am making some coding, this is only to upload img,jpg ,gif file format.I neeed to upload  ZIP/RAR format .can you help me?

sample code(this code only upload image file types)

Imports Microsoft.Win32
Imports Microsoft.SqlServer
Imports System.Data

Imports System.Data.SqlClient




Imports System.Windows
Imports System.IO



Public Class Form1

    'Dim mystream As Stream
    Dim mystream As IO.MemoryStream

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'this is for browse buton


        With odlg
            .InitialDirectory = "C:\"
            .Filter = "All Files|*.*|Bitmaps|*.bmp|GIFs|*.gif|JPEGs|*.dwg"
            .FilterIndex = 2
        End With
        If odlg.ShowDialog() = DialogResult.OK Then
            '04-03
            With PicSave
                .Image = Image.FromFile(odlg.FileName)
                .SizeMode = PictureBoxSizeMode.CenterImage
                .BorderStyle = BorderStyle.Fixed3D
            End With
            '---------------
            ' Label1.Text = Val(odlg.FileName)



            lblFilePath.Text = odlg.FileName
        End If

    End Sub


    Private Sub odlg_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles odlg.FileOk

    End Sub

    Private Sub sve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sve.Click
'this is for save button click   

    Dim ms As New IO.MemoryStream()

        PicSave.Image.Save(ms, PicSave.Image.RawFormat)
       
       
        Dim arrImage() As Byte = ms.GetBuffer()





        ' Dim arrImage() As Byte = mystream.GetBuffer





        'mystream.Close()


        Dim strFilename As String = lblFilePath.Text.Substring(lblFilePath.Text.LastIndexOf("\") + 1)
        ' Dim strFilename As String = Label1.Text.Substring(Label1.Text.LastIndexOf("\") + 1)
        Dim connectionstring As String
        connectionstring = "Data Source=CTECH002\SQLEXPRESS;initial catalog = TRACKERDB;USER ID=sa;password=sa"


        Dim cnn As New SqlConnection(connectionstring)

        ' connectionstring = "Data Source=CTECH002\SQLEXPRESS;initial catalog = TRACKERDB;USER ID=sa;password=sa"

        Dim strSQL As String = "INSERT INTO Picture (Filename, Picture)VALUES(@Filename, @Picture)"
        Dim cmd As New SqlCommand(strSQL, cnn)

        With cmd
            .Parameters.Add(New SqlParameter("@Filename", SqlDbType.NVarChar, 50)).Value = strFilename

            .Parameters.Add(New SqlParameter("@Picture", SqlDbType.Image)).Value = arrImage 'mystream

        End With

        cnn.Open()

        cmd.ExecuteNonQuery()

        cnn.Close()
        MsgBox("Updated")


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Form2.Show()
        Me.Hide()

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class




Answers (1)