Use a
FileUpload Control[
^] - this link includes an example.
Assuming you are using an SQL database, then Try:
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.";
}