1
我正在尝试合并一些代码,用于.net的代码,我发现原代码。 Ultimatley,我试图创建一个允许文件附件的表单。我所做的每件事都会产生错误,并且找不到可以识别我的问题的网站。这里是代码的形式...后面的合并代码
<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>
这里是代码背后。
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;
}
}
}
如何将它们合并到一个页面上?
包括您正在收到的错误消息的全文。 –