これがサーバー側のC#コードです
protected void btnUpload_Click1(object sender, EventArgs e)
{
HttpPostedFile file = Request.Files["btnFileUpload"];
if (file != null && file.ContentLength > 0)
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/App_Data/", fname)));
}
}
このコードは Chrome と Mozilla ではうまく機能しますが、8,9 ではRequest.Files["btnFileUpload"]
null になります。
これがhtmlです...
<form id="form1" runat="server" enctype="multipart/form-data">
<div class="fileName">
</div>
<div id="plus" class="uploadPlusBtn">
</div>
<input type="file" id="btnFileUpload" runat="server" />
<asp:Button ID="btnUpload" runat="server" OnClick="btnUpload_Click1" Text="Upload" />
</form>
そして追加されたjQuery
$(function () {
var wrapper = $('<div/>').css({ height: 0, width: 0, 'overflow': 'hidden' });
var fileInput = $('#btnFileUpload').wrap(wrapper);
$('#plus').click(function () {
fileInput.click();
});
});