Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to upload mp3 songs?????and also store in database in binary format...
plz help me..
thnks in advance
Posted

 
Share this answer
 
Use a FileUpload Control[^] - this link includes an example.

Assuming you are using an SQL database, then Try:
C#
if (fl.HasFile)
    {
    try
        {
        int version = 0;
        string filename = Path.GetFileName(fl.FileName);
        byte[] filedata = fl.FileBytes;
        string strCon = ConnectionStrings.Download;
        using (SqlConnection con = new SqlConnection(strCon))
            {
            con.Open();
            using (SqlCommand ins = new SqlCommand("INSERT INTO dlContent (fileName, dataContent) " +
                                                   "VALUES (@FN, @DT)", con))
                {
                ins.Parameters.AddWithValue("@FN", filename);
                ins.Parameters.AddWithValue("@DT", filedata);
                ins.ExecuteNonQuery();
                }
            }
        return string.Format("{0} uploaded", filename);
        }
    catch (Exception ex)
        {
        return "The file could not be uploaded. The following error occured: " + ex.Message;
        }
    }
return "Please select a file.";
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900