Struggling with this problem for days now, I could really use some fresh perspective.
My setup includes Windows Server 2012, IIS 8.0, and ASP.NET 4.5. I'm new to both IIS and ASP.NET, so please bear with me. The website I'm working on involves file uploads, which need to be validated before being stored on the server.
Initially, I attempted to use Javascript to validate the inputs before submission, but nothing gets uploaded. To simplify the process, I decided to try a basic upload without validation for now.
Here's the current state of the files:
upload_page.aspx
<html>
...
<script language="Javascript">
function validate()
{
var filter = <allowed file extensions>;
var file1 = document.getElementById("uploadfile1").value;
//perform checks
if(filter.test(file1))
{
return true;
}
else
{
return false;
}
}
</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);
}
}
Any suggestions on where I might be going wrong? Your help would be greatly appreciated. Thank you.