I’m using VS2017 and my browser is Microsoft Edge (unfortunately, no other browser, I must use this). Upon selecting the file I want to upload, the debugging immediately stops. Am I missing something?
I have below code for my Upload.aspx:
<form id="form1" method="post" runat="server" enctype="multipart/form-data" action="Upload.aspx">
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:Button ID="btnupload" runat="server" Text="Upload" OnClick="btnupload_Click1" />
<br />
<asp:Label runat="server" ID="UploadStatus"></asp:Label>
</form>
And I have below for my Upload.aspx.cs button:
protected void btnupload_Click1(object sender, EventArgs e)
{
if ((FileUpload1.PostedFile != null) && (FileUpload1.PostedFile.ContentLength > 0))
{
string fn = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Upload") + "\" + fn;
try
{
FileUpload1.PostedFile.SaveAs(SaveLocation);
UploadStatus.Text = "The file has been uploaded.";
}
catch (Exception ex)
{
UploadStatus.Text = "Error: " + ex.Message;
}
}
else
{
UploadStatus.Text = "Please select a file to upload.";
}
}