I am trying to upload multiple files on an aspx page using one FileUpload
control. I've set the control to allow for multiple files:
<asp:FileUpload ID="fuAttach" Multiple="Multiple" runat="server" Visible="False" />
Now, on the click of a button I want to take the data of each of these files and save it to a database (using a REST service, but that's not important right now). According to Visual Studio, I can access the PostedFile
property, but not the PostedFiles
property of the FileUpload
control.
'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?)
When debugging, however the PostedFiles
property is visible and contains all of my files:
Also, I tried using Request.Files, but this just gives me the id of the FileUpload
control:
Also, looking at the FileUpload
control, there is no PostedFiles
:
public class FileUpload : WebControl
{
public FileUpload();
public byte[] FileBytes { get; }
public Stream FileContent { get; }
public string FileName { get; }
public bool HasFile { get; }
public HttpPostedFile PostedFile { get; }
protected override void AddAttributesToRender(HtmlTextWriter writer);
protected internal override void OnPreRender(EventArgs e);
protected internal override void Render(HtmlTextWriter writer);
public void SaveAs(string filename);
}
Am I missing something here?
Go to "Application" tab in the project "Properties" and change the "Target Framework" to 4.5.