System.Web.UI.WebControls.FileUpload 在多个文件上传 Asp.net 期间出现“AllowMultiple”和“PostedFiles”问题

问题描述 投票:0回答:2

所以我尝试在asp.net 4.0中上传多个文件(图像)。我以前做过这个,就在不久前,这是有效的,我所做的就是尝试调试一个值,然后它开始哭泣。

我尝试过谷歌搜索(如果你想知道的话),但我找不到问题的解决方案。

所以这是aspx代码

<asp:FileUpload ID="FileUpload1" Multiple="Multiple" runat="server" />

在知道前者适用于 asp.net 4.5 及更高版本后,我将

AllowMultiple="true"
更改为
Multiple="Multiple"
,这很奇怪,因为它以前有效。

这是我的.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'.

asp.net file-upload
2个回答
3
投票

好吧,经过搜索和搜索,我确实找到了我的问题的答案。那就是

asp.net 4.0 不允许以某种方式进行多次上传。我必须使用一些插件或其他东西。


0
投票

是的,与

<compilation debug="true" targetFramework="4.0"/>

 if (fuPhoto.HasFiles)
            {
                PicsCount = fuPhoto.PostedFiles.Count;
            }

这是行不通的。 改变 targetFramwork 就像

<compilation debug="true" targetFramework="4.7.2"/>

它将完美地工作。

© www.soinside.com 2019 - 2024. All rights reserved.