This project is read-only.

Editing the list of Sections Available

Topics: Developer Forum, Project Management Forum, User Forum
Oct 28, 2008 at 7:06 PM
I would like to limit what is in the Section drop down on pages, when logged in as an admin user.  I have looked all over the code, but can not find where the list is generated and how to control it.  Thanks for any help.
Oct 28, 2008 at 9:37 PM
Edited Oct 28, 2008 at 9:40 PM
Hi ddarind

I have done this in the DropZone.
In web.config in appSetting I added a excludeSectionList that has a delimeter for each section that should be excluded. I guess this is easy to do with the main sections also.
  <add key="ExcludeSectionList" value="EventList|Gallery|ContactForm|DownloadList|Guestbook|Blog|SubPages" />


In page_load of default.aspx.cs, replace :

                SortedList sortedlist = new SortedList(list);
                for (int i = 0; i < sortedlist.Count; i++)
                {
                    string ResourceID = "ctl_" + sortedlist.GetKey(i).ToString() + "_RssTitle";
                    string ListName = Resources.StringsRes.ResourceManager.GetString(ResourceID);
                  
                    if (canAdd(sortedlist.GetKey(i).ToString().Trim())) //Only include sections that's not in list
                    {
                        cmbSections.Items.Add(new ListItem(ListName, sortedlist.GetByIndex(i).ToString()));
                    }
                }

Add the following method to default.aspx.cs


    /// <summary>
    /// Returns true if a section can be added to page
    /// Reads from a ExcludeSectionList in web.config
    /// <add key="ExcludeSectionList" value="RolesMapper|RoleEditor" /><!--Excluding sections i pages-->
    /// </summary>
    /// <param name="section">The section to check</param>
    /// <returns>If a section can be added</returns>
    private bool canAdd(string section)
    {
        bool val = true;
        if (ConfigurationManager.AppSettings["ExcludeSectionList"] == null)
            return val;

        string[] excludeList = ConfigurationManager.AppSettings["ExcludeSectionList"].ToString().Split('|');

        foreach (string item in excludeList)
        {
          
            if (section.Trim() == item.Trim())
            {
                val = false;
                break;
            }
            else
            {
                val = true;
            }
        }
        return val;
    }

Oct 29, 2008 at 9:43 PM
Worked perfectly.  Thanks for your help.
Jan 31, 2009 at 6:07 PM
Rickard,

I am using your solution. I am also utilizing the Exclude Key for the dropzone sections. Question, how can I extend this so I have 2 app keys, one for MainSections, one for DropZones?

Thank You,
TJ Havens
Feb 17, 2009 at 3:40 AM
Ok, I think I get it now.

Thanks,
TJ Havens