Ok there is the scenario: You want to create application which sets permission to the some user. To achieve your goal you can use
SPRole class,
SPRoleDeffinition class and
Web.RoleDefinitions property. If developing server is in English and production server in another language you probably get this error message
"Permission level cannot be found." . The cause of this error is simple - If you need to get "Full Control" role definition for web, you just type
SPRoleDefinition roleDef = web.RoleDefinitions["Full Control"]; and as you can see the name of role definition is in English and over my expectation the name is changed with language version :(
So how to solve this situation? (Please keep in mind, I didn't found any better solution so do not hesitate to comment it. I am always open to learn something new :) )
- You can write your code just for particular language version.
- I would create dictionary for each language version and check current language version (SPContext.Current.Web.Language)
Get ID of SPRoleDefinition and use it instead of name
using (SPSite site = new SPSite("http://serverName/"))
{
using (SPWeb web = site.OpenWeb())
{
for (int i = 0; i < web.RoleDefinitions.Count; i++ )
{
Console.WriteLine(web.RoleDefinitions[i].Name + " " + i);
}
}
}
I am sorry to everybody who tried the second solution. This really is not the way because the RoleDefinition ID can be different too. So as far as I know the only way to achieve this is the first point. Kind of bothering, isn't it?
That all I found so maybe it can be useful.... ;)
No comments:
Post a Comment