allowmultiple =“true”的代码是什么? (上传文件) [英] What is the code for allowmultiple=“true”? (fileupload)
本文介绍了allowmultiple =“true”的代码是什么? (上传文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I want to upload multiple files with fileupload. That works :) But it should upload multiple files with a Limit of 5 files.
Here is my behind code:
protected void btnUpload_Click(object sender, EventArgs e)
{
StartUpLoad();
}
private void StartUpLoad()
{
string imgName = FileUpload1.FileName;
string imgPath = "~/Uploads/" + imgName;
int imgSize = FileUpload1.PostedFile.ContentLength;
string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName);
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
if (ext.ToUpper().Trim() != ".JPG" && ext.ToUpper() != ".PNG" && ext.ToUpper() != ".GIF" && ext.ToUpper() != ".JPEG")
{
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Only .jpg, .png oder .gif!')", true);
}
else
{
FileUpload1.SaveAs(Server.MapPath("~/Uploads/") + FileUpload1.FileName);
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Saved!')", true);
}
}
}
我尝试过:
我想,应该有点数......但我不确定.....
What I have tried:
I think, that there should be something with count...but I am not sure.....
推荐答案
参考 - 在Visual Studio 2012和2013中使用ASP.Net 4.5 FileUpload控件上载多个文件 [ ^ ]。
FileUpload.PostedFiles
会给你一个Count方法来计算文件数。
Refer - Upload multiple files with ASP.Net 4.5 FileUpload control in Visual Studio 2012 and 2013[^].
FileUpload.PostedFiles
would give you a Count method to count the number of files.
这篇关于allowmultiple =“true”的代码是什么? (上传文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文