1
votes

I want to add a custom RoleDefinition to my sharepoint site, in VS2010 I added a new feature receiver and under the Activated Event I added this code:

using (SPSite site = new SPSite("http://localhost:8280"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.RoleDefinitions.Add(AdminRole);
                    web.Close();
                 }
                site.Close();

            }

Using the package designer I added the feature and from VS I deploy the solution to the "Web" scope. when I go to site features I do see my feature being Active but the Role Definition is not there. I suspect the Event receiver code not being fired so I added some code that writes to a log file and there the file was empty so the code is never reached. knowing that the solution is deployed as a sandbox solution on SharePoint 2010.

any ideas?

Many thanks

2
How did you deploy feature? Using visual studio? Have you tried deactivate and activate feature again?Yevgeniy.Chernobrivets
Yes I've tried to activate and desactivate many times, code is unreachableuser998824
Did you do iisreset after deployment? It could be caching issue. Also try to open wsp packages using archiver and check feature xml declaration file. Maybe there is incorrect assembly name or namespace.Yevgeniy.Chernobrivets
tried it all doesn't workuser998824

2 Answers

1
votes

The Event receiver did not fire because it was not linked to the feature...doh! here is the thing, in the feature template file these two attributes must be added: ReceiverAssembly="Full name, version, neutral,publikeytoken" ReceiverClass="*Namesapace.classname"

hth

0
votes

You created some code that got deployed within a feature. But you never do something to make that code run. I assume you have a business reason to do this in code in a feature, as the UI would let you do this sort of thing. Your code should actually be within a feature receiver if it is something you want to execute upon activating the feature. You would add this code to the override routine for the feature activating class.

Search for Feature receiver for detailed instruction.