So I'm trying to upload multiple files (images) in asp.net 4.0. I have done this before and just a little time ago this was working and all I did was try to debug a value and after that it started crying.
I have tried googling (in case you wonder) but I can't find the solution to my problem.
So here's the aspx code
<asp:FileUpload ID="FileUpload1" Multiple="Multiple" runat="server" />
I changed the AllowMultiple="true"
to Multiple="Multiple"
after knowing the former is for asp.net 4.5 and above and that's weird because it worked before.
This is my .cs code.
foreach (var file in FileUpload1.PostedFiles)
{
string filename = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath("../Pics/" + filename));
SqlCommand cmd = new SqlCommand("Insert into slider(photo) values(@ImagePath)", conn);
cmd.Parameters.AddWithValue("@ImagePath", filename);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
It gives a blue underline on PostedFiles and the error reads
"'System.Web.UI.WebControls.FileUpload' does not contain a definition for 'PostedFiles' and no extension method 'PostedFiles' accepting a first argument of type 'System.Web.UI.WebControls.FileUpload' could be found (are you missing a using directive or an assembly reference?)"
And another error also appears:
"'System.Web.UI.WebControls.FileUpload' does not contain a definition for 'AllowMultiple' and no extension method 'AllowMultiple' accepting a first argument of type 'System.Web.UI.WebControls.FileUpload' could be found (are you missing a using directive or an assembly reference?)"
And after changing it to Multiple="Multiple"
I'm getting this following warning:
Validation (ASP.Net): Attribute 'Multiple' is not a valid attribute of element 'FileUpload'.
Okay so, after searching and searching I did find the answer to my issue. And that is
asp.net 4.0 does not allow multiple upload somehow. I'll have to use some plugin or something.