在 SharePoint 2007 中部署的 Web 控件

本文关键字:Web 控件 部署 SharePoint 2007 | 更新日期: 2023-09-27 17:56:58

protected void btn_Submit_Click(object sender, EventArgs e)
        {
            lbl_EmpCode.Text = "";
            SPSite newsites = SPContext.Current.Site;
            SPWeb webs = newsites.OpenWeb();

            SPQuery query = new SPQuery();
            query.Query = string.Format ( "<Query>" +"<Where>"+ "<Eq>"+ "<FieldRef Name='Company_x0020_Code' />"+" <Value Type='Text'>"+ txt_Companycode.Text +"</Value>"+" </Eq>"+" </Where>"+" </Query>");
            SPList list = webs.Lists["Companies"];
            SPListItemCollection items = list.GetItems(query);

            if (items.Count > 0)
            {
                txt_Companycode.Text = "";
                Response.Redirect("Pages/ClaimAccount.aspx");
            }
            else
            {
                lbl_EmpCode.Text = "Company Code is not Matching with the Exisiting Record..!";
                txt_Companycode.Text = "";
                Response.Redirect("Pages/CompanyCodeCheck.aspx");
            }
        }

我的代码有什么问题?在此代码中,我通过TextBox作为公司代码从用户那里获取数据,然后与 SharePoint 列表进行比较。如果匹配,请转到下一页,如果不匹配,则保持在同一页面上并给出错误。

在 SharePoint 2007 中部署的 Web 控件

从字符串(query.查询)直接从 where 标记构建 CAML