Question

i need read whole resx file in code behind. I did this in this way:

ResXResourceReader rsxrOrganizationSubtypes = new ResXResourceReader(@"D:\DNN_Cafaas\DesktopModules\OPEGIEKA.DNN.Modules.CreateInstitution\App_LocalResources\OrganizationSubtypes.resx");
rsxrOrganizationSubtypes.UseResXDataNodes = true;
IDictionaryEnumerator dict = rsxrOrganizationSubtypes.GetEnumerator();
while (dict.MoveNext())
{
    ResXDataNode node = (ResXDataNode)dict.Value;
}

Is there any possibility to sort/order results from resx file ? For example by Name ?

Resolved (sorted by value from resx file). Maybe there is better way to do it, but its working:

ResXResourceReader rsxr = new ResXResourceReader(PathToResX);
rsxr.UseResXDataNodes = true;

IDictionaryEnumerator dictRSXR = rsxr.GetEnumerator();
SortedDictionary<string, string> sortedRSXR = new SortedDictionary<string, string>();

while (dictRSXR.MoveNext())
{
    ResXDataNode node = (ResXDataNode)dictRSXR.Value;
    sortedRSXR.Add(node.GetValue((ITypeResolutionService)null).ToString(), node.Name);
}

foreach (KeyValuePair<string, string> p in sortedRSXR)
{
    counterDDL++;
    dropDownList.Items.Insert(counterDDL, new ListItem(p.Key, p.Value));                                
}
Was it helpful?

Solution

You could add keys and values to a SortedDictionary<string, ResXDataNode> in the while loop. This should sort your entries automatically.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top