ASP.net 文件上传 - 文件字节、文件名
本文关键字:文件 字节 文件名 net ASP | 更新日期: 2023-09-27 18:32:16
嗨,我在ASP中使用文件上传控件。 我无法在 C# 代码中获取文件名或文件字节数
.aspx
Upload Image: <asp:FileUpload runat="server" ID="fu" />
<asp:LinkButton ID="lnkContinue" runat="server" class="ButtonGeneric" onCommand="lnkContinue_Click">CLICK</asp:LinkButton>
cs 代码
protected void btnNext_Click(object sender, EventArgs e)
{
string fileName = fu.FileName;
int DocumentID = DocumentsComponent.SaveFileByJobID(JobId, UserID, fileName,fu.FileBytes, txtDescription.Text, 1);
}
我可能不得不将字节存储到一个字节变量中,但我仍然没有在文件名字符串中填充任何内容。
母版页中的"更新"面板:
<div id="content">
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true" ID="up" UpdateMode="Conditional">
<ContentTemplate><asp:ContentPlaceHolder id="cph" runat="server" /></ContentTemplate>
</asp:UpdatePanel>
</div>
用
以下命令包装您的代码:
if(isPostBack)
{
string fileName = fu.FileName;
int DocumentID = DocumentsComponent.SaveFileByJobID(JobId, UserID, fileName,fu.FileBytes, txtDescription.Text, 1);
}
在提交文件之前,还要检查是否未使用 AJAX 或页面加载时重新加载文件上载控件。
为了关注
这篇文章的其他用户的利益,#banana 帮助我朝着正确的方向前进,问题在于我引用的母版页中使用的更新面板,删除更新面板将完成这项工作。 如果我想保留更新面板,我需要使用触发器,这超出了本文的范围。