zoukankan      html  css  js  c++  java
  • sharepoint 插入字段类型为People and group

      绑定类型为People and group

    private void BindOwner()
             {
                 using (SPSite site = new SPSite(siteurl))
                 {
                     using (SPWeb web = site.OpenWeb())
                     {
                         DataTable ownerTable = Make_Table();
                         foreach (SPUser user in web.SiteGroups["Owner"].Users)
                         {
                             if (user.Name != "System Account")
                             {
                                 DataRow row = ownerTable.NewRow();
                                 row["Name"] = user.Name;
                                 row["LoginName"] = user.LoginName;
                                 ownerTable.Rows.Add(row);
                             }
                         }
                         DropDownListOwner.DataSource = ownerTable;
                         DropDownListOwner.DataTextField = "Name";
                         DropDownListOwner.DataValueField = "LoginName";
                         DropDownListOwner.DataBind();
                     }
                 }
             }


             private DataTable Make_Table()
             {
                 DataTable nameTable = new DataTable("Names");
                 nameTable.Columns.Add("Name");
                 nameTable.Columns.Add("LoginName");
                
                 return nameTable;
             }

    插入时需注意的:

       using (SPSite site = new SPSite(siteurl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        try
                        {
                            site.AllowUnsafeUpdates = true;
                            web.AllowUnsafeUpdates = true;
                            SPList list = web.Lists["AuditSystem"];
                            item["Owner"] = web.SiteUsers[DropDownListOwner.SelectedValue];
                             item.Update();
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(ex.Message);
                        }
                    }

  • 相关阅读:
    [CF451E] Devu and Flowers
    [CF1038E] Maximum Matching
    [CF825E] Minimal Labels
    [CCPC2020绵阳L] Lottery
    [CCPC2020绵阳K] Knowledge is Power
    [CCPC2020绵阳J] Joy of Handcraft
    [CCPC2020绵阳G] Game of Cards
    [CCPC2020绵阳D] Defuse the Bombs
    [CF1082E] Increasing Frequency
    [CF301B] Yaroslav and Time
  • 原文地址:https://www.cnblogs.com/KingStar/p/1592736.html
Copyright © 2011-2022 走看看