我有一个带有表格标签
的母版页<form id="form1" runat="server" enctype="multipart/form-data" method="post">
在页面中我有HtmlInputFile
<input id="File1"
type="file"
accept="image/*"
runat="server"/>
<input type="button"
id="Button1"
value="Upload"
OnServerClick="Button1_Click"
runat="server"/>
和处理程序
void Button1_Click(object Source, EventArgs e)
{
if (File1.PostedFile != null)
{
try
{
HttpPostedFile file = File1.PostedFile;
byte[] fileContent = new byte[file.ContentLength];
file.InputStream.Read(fileContent, 0, file.ContentLength);
}
catch (Exception exc)
{
}
}
}
但总是发表文章= null !!!!
答案 0 :(得分:2)
尝试使用ASP.NET控件:
<asp:FileUpload id="File1" runat="server" />