我正在寻找一种<input type="file" multiple="multiple">
在我的 asp.net 3.5 项目中完美管理 HTML 5 标记的方法。我之前在页面上使用了一个控件,但是如果我们在同一页面上有多个上传控件怎么办。请看我的代码:
protected void btnSave_Click(object sender, EventArgs e)
{
//---------Need to check if my upload control has files: Please suggest a perfect way
if (fupAttachment.PostedFile != null || fupAttachment.PostedFile.FileName != "" || fupAttachment.PostedFile.ContentLength>0)//here is a problem, as it does not checks for a blank file upload control
HttpFileCollection hfc = Request.Files;
string strDirectory = Server.MapPath("~/") + "Mailer/" + hidCampID.Value;
if (hfc.Count>0)
{
if (!System.IO.Directory.Exists(strDirectory))
{
System.IO.Directory.CreateDirectory(strDirectory);
}
if (System.IO.Directory.Exists(strDirectory))
{
for (int i = 0; i < hfc.Count - 1; i++)
{
hfc[i].SaveAs(strDirectory + "/" + hfc[i].FileName.Replace(" ", "_"));
}
}
}
}
}
我的asp页面是这样的:
//----this control is from which I want to multiple upload files
<input type="file" multiple="multiple" runat="server" id="fupAttachment" />
// Another upload control is there which takes input when page loads
<asp:FileUpload ID="fupMailingList" runat="server" />
所以,正是我的问题是,当页面加载“fupMailingList”时已经获取了一个文件,然后当我想使用我的多个上传控件“fupAttachment”时,我无法检查它是否有任何文件,因为hfc
检查所有上传控件并在其中一个中获取文件。所以,请告诉我一种只检查“fupAttachment”控件的方法,然后正确地完成我的工作。