Domanda

I am working on developing an event receiver inside my sharepoint 2013 farm on-premises. and inside the event receiver i am trying to assign a list column to a SPGroup.

what i am trying to do is similar to the following steps using the UI:-

  1. Go to a list settings.
  2. click on the column at the list level.
  3. override the column to be linked to a specific group (for example Approvers) instead of All Users as defined inside the site column level. enter image description here

Now here is my code inside the ER:-

SPGroup newgroup = site.RootWeb.SiteGroups[currentgroupname + " Members - " + curItemID.ToString()];
foreach (SPList splist in newSite.Lists)
 {
   if (splist.Title.ToLower() == "action")
       {
         SPFieldUser spfield = splist.Fields["ActionOwner"] as SPFieldUser;
         spfield =  newgroup as SPGroup;
       }
  }

But i am getting the following syntax error on this spfield = newgroup as SPGroup;

Cannot implicitly convert type 'Microsoft.SharePoint.SPGroup' to 'Microsoft.SharePoint.SPFieldUser'

È stato utile?

Soluzione

Try:

spfield.SelectionGroup = newgroup.ID;
spfield.Update();
spList.Update();

MSDN: SPFieldUser.SelectionGroup property

Sample: Programmatically Set "Person Or Group" Column To Select User From A Specified Group

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top