System.Web.UI.WebControls.FileUpload”不包含“ HasFiles”的定义,也没有扩展方法

时间:2019-10-14 11:16:04

标签: asp.net

使用asp.net,我想使用单个文件上传选项上传多个文件,但我得到 System.Web.UI.WebControls.FileUpload'不包含'HasFiles'的定义,并且扩展方法错误。

我的代码:

<%-- ed: some styles removed for readability. --%>
<div class="col-md-3">
    <asp:Label ID="lblattach" runat="server" Text="Attach File:"></asp:Label>
    <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true"></asp:FileUpload>
</div>

if (FileUpload1.HasFiles)
{
    if (FileUpload1.FileName.EndsWith(".pdf") || 
        FileUpload1.FileName.EndsWith(".PDF") || 
        FileUpload1.FileName.EndsWith(".doc") || 
        FileUpload1.FileName.EndsWith(".DOC") || 
        FileUpload1.FileName.EndsWith(".docx") || 
        FileUpload1.FileName.EndsWith(".DOCX"))
    {
        foreach (HttpPostedFile PostedFiles in FileUpload1.PostedFiles)
        {
            FileInfo TheFile = 
                new FileInfo(MapPath("~/Ebooks") + "\\" + FileUpload1.FileName);
            if (TheFile.Exists)
            {
                Label1.Visible = true;
                Label1.Text = "File '" + FileUpload1.FileName + "' Already Exists";
            }
            else
            {
                string fileName = Path.GetFileName(PostedFiles.FileName);
                PostedFiles.SaveAs(Server.MapPath("~/Ebooks") + "\\" + fileName);
                {
                    Con.Open();
                    string sql1 = "Sp_InsertEbookLinks";
                    SqlCommand cmd = new SqlCommand(sql1, Con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@linkName", link);
                    cmd.Parameters.AddWithValue("@fileName", FileUpload1.FileName);
                    cmd.Parameters.AddWithValue("@BatchCode", ddlbatch.SelectedValue);
                    cmd.Parameters.AddWithValue("@CourseCode", ddlcourse.SelectedValue);
                    cmd.Parameters.AddWithValue("@SemesterCode", ddlSemester.SelectedValue);
                    cmd.Parameters.AddWithValue("@SubjectCode", ddlsubject.SelectedValue);
                    cmd.Parameters.AddWithValue("@ActiveInactive", chkbxactinact.Checked);
                    cmd.Parameters.AddWithValue("@lastModUserCod", 1);
                    cmd.ExecuteNonQuery();
                    Con.Close();
                    ScriptManager.RegisterStartupScript(this, GetType(), "Popup", 
                        "Successalert('Data Inserted Successfully');", true);
                    LoadData();
                    txtlink.Text = "";
                    ddlbatch.SelectedValue = "0";
                    ddlcourse.SelectedValue = "0";
                    ddlSemester.SelectedValue = "0";
                    ddlsubject.SelectedValue = "0";
                    Label1.Visible = false;
        }
    }
}

0 个答案:

没有答案