使用文章中的想法
Uploading Files in ASP.net without using the FileUpload server control,我正在尝试使用隐藏input type="file"
上传文件,使用下一个:
在aspx文件中:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript">
function uploadfile()
{
var ctl = document.getElementById('myFile');
ctl.click();
}
</script>
</head>
<body>
<form id="form2" runat="server" enctype="multipart/form-data">
<input type="file" id="myFile" name="myFile" style="display:none" />
<asp:Button runat="server" ID="btnUpload" Text="Upload" OnClientClick="uploadfile();" />
</form>
</body>
</html>
代码文件中的:(我只是想确保检索文件)
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpload.Click
Dim file As HttpPostedFile = Request.Files("myFile")
If file Is Nothing Then Throw New IO.FileNotFoundException
End Sub
但是后期永远不会发生,如何解决这个问题?