More in this section

Forums / Developing with Sitefinity / Setting RadEditor Toolsfile Programmatically

Setting RadEditor Toolsfile Programmatically

8 posts, 2 answered
  1. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    24 Aug 2009
    Link to this post
    Hello,

    A client has requested that in the forums, different groups of users should be allowed to use different tools. Specifically, they requested that "troublemaking" users be denied the ability to upload documents to posts. Administrators should be able to check a checkbox in the Sitefinity back-end which would restrict a specific user.

    So far, I have created separate ToolsFile.xml's containing the appropriate tools for each group, and I have created a checkbox field in Users.aspx as well in the web.config file. Firstly, the checkbox doesn't stay checked. Is this because checkboxes aren't supported? Once that issue is resolved, what would be the best way to bind the rad editor in /Sitefinity/ControlTemplates/Forums/EditPost.ascx to this checkbox value so that the appropriate ToolsFile.xml is displayed?

    Thank you very much,

    David
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Aug 2009
    Link to this post
    Hello David,

    It seems that there is a problem related to updating the controls value when editing profile data. Actually the value is saved t the database.

    Below is a code that you can add to Users.aspx.cs.
    protected override void OnPreRender(EventArgs e) 
        { 
            base.OnPreRender(e); 
            Control container = manageUsers.GetCurrentContainer(); 
     
            if (container is ManageUsers.EditContainer) 
            { 
                ManageUsers.EditContainer editCont = container as ManageUsers.EditContainer; 
                ManageProfile.EditContainer editProfile = editCont.ProfileControl.Controls[0] as ManageProfile.EditContainer; 
                if (editProfile != null
                { 
                    CheckBox cbox = editProfile.GetControl<CheckBox>("box"false); 
                    ProfileBase pBase = ProfileBase.Create(editCont.ProfileControl.Username); 
                    object obj = pBase.GetPropertyValue("box"); 
                    if (obj.Equals(true)) 
                    { 
     
                        cbox.Checked = true
                    } 
                    else 
                    { 
                        cbox.Checked = false
                    } 
                } 
                
            } 
     
        } 

    To set different ToolsFile for the RadEditor of EditPost template the best way could be dividing users per roles.

    Sample code:

    public partial class Sitefinity_ControlTemplates_Forums_EditPost : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (UserManager.IsCurrentUserInRole("test")) 
            { 
                // or use ProfileBase as shown in the sample above. 
                tbQuote.ToolsFile = "~/Sitefinity/ControlTemplates/Forums/ToolsFile1.xml"
                editor.ToolsFile = "~/Sitefinity/ControlTemplates/Forums/ToolsFile1.xml"
            } 
        } 
     


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Answered
  3. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    24 Aug 2009
    Link to this post
    Thank you for your timely response.

    I considered splitting the users up in different roles, and the reason why I decided not to implement it that way, is because the users are in a consistent role, (which is already determining other site functions), but they will fluctuate in and out of this state. Essentially what this checkbox means is that while the checkbox for a specific user is checked, that person is on "timeout", and are therefore limited with the functions they can perform when posting in the forums, for example, uploading files. It is possible that they can quickly gain these privileges back, with the unclick of the option.

    If you feel that this implementation would be more complicated than it's worth, I will be willing to try creating an "In Timeout" role, and direct the clients to use this method.

    Thank you,
    David
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    24 Aug 2009
    Link to this post
    Hi David,

    You can use ProfileBase as the comment shows in the code sample above. Below is the implementation that gets the value of "box" control and loads custom ToolsFile.

    public partial class Sitefinity_ControlTemplates_Forums_EditPost : System.Web.UI.UserControl 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (UserManager.IsCurrentUserInRole("test")) 
            { 
                string uName = UserManager.GetCurrentUserName(); 
                ProfileBase pBase = ProfileBase(uName); 
                object obj = pBase.GetPropertyValue("box"); 
                if (obj.Equals(true)) 
                { 
     
                    ctbQuote.ToolsFile = "~/Sitefinity/ControlTemplates/Forums/ToolsFile.xml"
                    editor.ToolsFile = "~/Sitefinity/ControlTemplates/Forums/ToolsFile1.xml 
                } 
                else 
                { 
                   // some other ToolsFiles. 
                }  
                 
            } 
        } 

    Let us know if there is anything else that we can do for you.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Answered
  5. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    31 Aug 2009
    Link to this post
    Hello,

    I have implemented this, and it is working fine locally. When I move it to the server, however, the control throws this error: Error BC30205: End of statement expected.

    I have implemented the Page_Load code in EditPost.ascx, with a few changes. When I test it locally on my machine, using IIS6, it works, but uploading it to my production server, which is IIS7, throws the above error. Here is my modified code:

    <script type="text/C#" runat="server"
     
        protected void Page_Load(object sender, EventArgs e)  
        {  
            string uName = Telerik.Security.UserManager.GetCurrentUserName();  
            System.Web.Profile.ProfileBase pBase = System.Web.Profile.ProfileBase.Create(uName);  
            object obj = pBase.GetPropertyValue("RestrictPostFeatures");  
            if (obj.Equals(true))  
            {  
               editor.ToolsFile = ResolveUrl("~/Sitefinity/ControlTemplates/Forums/RestrictedToolsFile.xml"); 
            }  
            else  
            {  
               editor.ToolsFile = ResolveUrl("~/Sitefinity/ControlTemplates/Forums/ToolsFile.xml"); 
            } 
        }  
    </script> 



    Any ideas why this would be happening?

    Thank you for your support,
    David
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    31 Aug 2009
    Link to this post
    Hello David,

    Try adding <%@ Control Language="C#" %> in the template and then use <script runat="server"> ...</script>. If the problem persists just separate the code by creating a code behind of the control template.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. David
    David avatar
    50 posts
    Registered:
    14 Jan 2009
    31 Aug 2009
    Link to this post
    That did it, thanks!

    David
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    31 Aug 2009
    Link to this post
    Hello David,

    Always glad to help.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
8 posts, 2 answered