I am trying to merge some code behind code for .net that I found with the original code. Ultimatley, I am trying to create a form that allows file attachments. Everything I do produces an error and I can’t find a site that identifies my problem. Here is the code for the form…
<form id="form1" runat="server">
<asp:FileUpload id="FileUploadControl" runat="server" />
<asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" />
<br /><br />
<asp:Label runat="server" id="StatusLabel" text="Upload status: " />
</form>
And here is the code behind.
protected void UploadButton_Click(object sender, EventArgs e)
{
if(FileUploadControl.HasFile)
{
try
{
string filename = Path.GetFileName(FileUploadControl.FileName);
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
StatusLabel.Text = "Upload status: File uploaded!";
}
catch(Exception ex)
{
StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
}
}
}
How do I merge these onto one page?
At the start of the file, add this…
I personally wouldn’t advise having code and markup on the same page – I think they should be in separate files