The problem I am facing is getting the file information from <input type=file>without using it <form>in the code method. The file is always returned as null in the code when I try to get information using Request.Files, and I believe that this is because it is never sent to the server.
In any case, to get the file information sent to the server without using <form>?
Here is the html that I am using
<input type="file" id="upload_file" name="upload_file" runat="server" accept="image/*" onchange="copyFile()" /> >
And this is the code for
HttpPostedFile file = Request.Files["upload_file"];
if (file != null && file.ContentLength > 0)
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
}
code>
<form> - -, IE ( IE9), css. , <input type=file>, <asp:FileUpload>, onchange.
!
, -, , runat = "server". , , , runat = "server" ,
! !
!
@bkwint, @TrizZz, .
html
<asp:FileUpload id="upload_file" runat="server" OnLoad="upload_file_OnLoad" /> >
onchange asp: FileUpload
protected void upload_file_OnLoad(object sender, EventArgs e)
{
((System.Web.UI.WebControls.FileUpload)sender).Attributes.Add("onchange", "copyFile();");
} >
if (Request.Files.Count > 0)
{
if (Request.Files[0].FileName.Length > 0)
{
Request.Files[0].SaveAs("~/App_Data/" + Request.Files[0].FileName);
}
} >
javascript, , asp: FileUpload. Id aspnetForm - , .
document.getElementById('aspnetForm').submit(); >
, , , , , , css , , , . , , , - , . submit , , , .
, / !
IE , . IE , .