Question

I created one event receiver and deployed it, but only users who are site collection admins are able to view this web part. I have included the SPSecurity.RunWithElevatedPrivileges but the same thing. What am I missing?

Below is my code

 public override void ItemAdding(SPItemEventProperties properties)
    base.ItemAdding(properties);
    SPSecurity.RunWithElevatedPrivileges(delegate()
       {SPWeb web = properties.OpenWeb();
        base.ItemAdding(properties);
        string name= web.Lists[properties.ListId].Fields["first name"].InternalName; 
        var list = web.Lists["location names"]; 
  });}
Était-ce utile?

La solution

You should recreate context.

SPSecurity.RunWithElevatedPrivileges(delegate() 
{
   using(SPSite site = new SPSite(properties.SiteId))
   {
      using(SPWeb web = site.OpenWeb(properties.Web.ID))
      {
          //code
      }
   }   
});   

Autres conseils

Please make sure that your solution is a farm solution, not a sandbox solution.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top