I have been pounding my head on this issue for several days and could use some help, maybe a fresh set of eyes would help.
I have Windows Server 2012, IIS 8.0 and ASP.NET 4.5. I am new to both IIS and ASP.NET so please be patient with me. The website I am trying to build allows the user to upload files which will first be checked to make sure they are valid and then will be placed on a folder on the web server.
I tried having the Javascript validate the inputs first before submitting the form to the server. However, nothing is uploaded so I decided to do one step at a time and just do a simple upload (without Javascript validation, for now).
Here is currently how the files stand:
upload_page.aspx
<html>
...
<script language="Javascript">
function validate()
{
var filter = <allowed file extensions>;
var file1 = document.getElementById("uploadfile1").value;
//do the checks
if(filter.test(file1))
{
returnval = true;
}
else
{
returnval = false;
}
return returnval;
}
</script>
...
<body>
<form method="post" runat="server" name="upload" enctype="multipart/form-data">
<asp:FileUpload ID="uploadfile1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" onClientClick="btnUpload_Click" />
<asp:Button ID="btnReset" runat="server" Text="Reset" />
</form>
</body>
</html>
upload_page.aspx.cs
protected void btnUpload_Click(object sender, EventArgs e)
{
if(this.uploadfile1.HasFile)
{
this.uploadfile1.SaveAs("C:\\inetpub\\wwwroot\\uploaded_files\\" + this.uploadfile1.FileName);
}
}
If anyone can tell me what I'm doing wrong it would be greatly appreciated! Thanks.