.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal

Home >> Code Snippets >> File Operation >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Upload audio files through VB.NET

Posted By:nishithraj       Posted Date: December 24, 2009    Points: 10    Category: File Operation    URL: http://www.dotnetspark.com  

Following is the code to upload multiple audio files through VB.NET

Here first we need to   Gets the Size, Audio Type  of the Audio. Then Read the Audio using read function of FileUpload1.PostedFile.InputStream

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) 
    Dim intAudioSize As Int32 = 0
    Dim strAudioType As String = Nothing
    Dim AudioStream As Stream = Nothing     

    intAudioSize = FileUpload1.PostedFile.ContentLength     

    strAudioType = FileUpload1.PostedFile.ContentType 
    AudioStream = FileUpload1.PostedFile.InputStream
    Dim AudioContent As Byte() = New Byte(intAudioSize) {}
    Dim intStatus As Integer = 0
    intStatus = AudioStream.Read(AudioContent, 0, intAudioSize)
    ' Create Instance of Connection and Command Object
    Dim myConnection As New SqlConnection(ConfigurationManager.AppSettings("ConnectionString"))
    Dim myCommand As New SqlCommand("Insert into AudioTable (Audio,AudioType) Values (@Audio,@AudioType)", myConnection)
    ' Mark the Command as a SPROC/Query
    myCommand.CommandType = CommandType.Text
    ' Add Parameters to SPROC
    Dim prmAudio As New SqlParameter("@Audio", SqlDbType.Image)
    prmAudio.Value = AudioContent
    Dim prmAudioType As New SqlParameter("@AudioType", SqlDbType.VarChar, 255)
    prmAudioType.Value = strAudioType
        Response.Write("New audio file uploaded successfully!")
    Catch SQLexc As SqlException
        Response.Write("Insert Failed. Error Details are: " & SQLexc.ToString())
    End Try
End Sub


Further Readings:

Author: Nikhil Kumar         Company URL: http://www.dotnetspark.com
Posted Date: January 11, 2010

Show the code for retrieving and playing the audio files in asp.net also :)

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend