因此,我试图在asp.net 4.0中上传多个文件(图像)。我以前也这样做过,就在不久前,这个方法还在工作,我所做的只是尝试调试一个值,然后它就开始哭泣了。
我尝试过谷歌搜索(万一你想知道),但我找不到解决问题的方法。
下面是aspx代码
<asp:FileUpload ID="FileUpload1" Multiple="Multiple" runat="server" />
我将AllowMultiple="true"更改为Multiple="Multiple",因为我知道前者适用于asp.net 4.5及更高版本,这很奇怪,因为它以前起过作用。
这是我的.cs代码。
foreach (var file in FileUpload1.PostedFiles)
{
string filename = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath("../Pics/" + filename));
SqlCommand cmd = new SqlCommand("Insert into slider(photo) values(@ImagePath)", conn);
cmd.Parameters.AddWithValue("@ImagePath", filename);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}它在PostedFiles上给出蓝色下划线,错误读取
"'System.Web.UI.WebControls.FileUpload' does not contain a definition for 'PostedFiles' and no extension method 'PostedFiles' accepting a first argument of type 'System.Web.UI.WebControls.FileUpload' could be found (are you missing a using directive or an assembly reference?)"
此外,还出现了另一个错误:
"'System.Web.UI.WebControls.FileUpload' does not contain a definition for 'AllowMultiple' and no extension method 'AllowMultiple' accepting a first argument of type 'System.Web.UI.WebControls.FileUpload' could be found (are you missing a using directive or an assembly reference?)"
在将其更改为Multiple="Multiple"后,我将收到以下警告:
Validation (ASP.Net): Attribute 'Multiple' is not a valid attribute of element 'FileUpload'.
发布于 2015-01-23 17:21:18
好吧,在搜索之后,我找到了我的问题的答案。那就是
asp.net 4.0不允许多次上传。我得用些插件什么的。
https://stackoverflow.com/questions/28114977
复制相似问题