1) Generate XML with desired tags
<?xml version="1.0"?>
<FLSecurity>
<MainForm Type="CoreForm" Name="EmployeeDetails.aspx" DisplayName="Employee Details Management">
<SubForms>
<SubForm Name="EmployeeDetails.ascx" DisplayName="Employee Details">
<Controls>
<Control Type="DataBound" DisplayName="Business Unit" ID="OrgStructureName" ParentControl="Grid" AssociateControl="lblOrgStructure">
<UserRoles>
<Role ID="1" DisplayName="BC Admin">
<IsVisible>True</IsVisible>
<IsEnabled>True</IsEnabled>
</Role>
</UserRoles>
</Control>
</Controls>
</SubForm>
</SubForms>
</MainForm>
</FLSecurity>
2) Generate XSD from XML
xsd file.xml {/classes | /dataset} [/element:element]
[/language:language] [/namespace:namespace]
3)Create XSD to Code
Happy Coding…
public class FLSecurityHelper
{
private static FLSecurity m_FLSecurity = null;
public static FLSecurity FlSecurityXml
{
get
{
if (m_FLSecurity == null)
{
//TASK: Load xml file form sharepoint list
string filepath = @"D:\utilities for testing\Ecm360.FLSecurity\FLSecurity.xml";
m_FLSecurity = FLSecurity.LoadFromFile(filepath);
}
return m_FLSecurity;
}
}
public static bool IsControlHidden(string formType, string mainForm, string subForm, string fieldID, List<string> userRolesIDs)
{
bool isControlHidden = true;
try
{
List<Control> formControls = FlSecurityXml
.Items
.Where(mf => mf.Type == formType && mf.Name == mainForm).FirstOrDefault()
.SubForms
.Where(sf => sf.Name == subForm)
.SelectMany(x=> x.Controls).ToList<Control>();
isControlHidden = formControls
.Where(ct => ct.ID == fieldID)
.ToList()
.FirstOrDefault()
.UserRoles
.Where(rl => rl.IsVisible == "False"
&& userRolesIDs.Contains(rl.ID)
).Count() > 0;
}
catch (Exception)
{
//throw;
}
return isControlHidden;
}
}
No comments:
Post a Comment