Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • gibbo 2 posts 22 karma points
    Jan 22, 2012 @ 22:55
    gibbo
    0

    Help please

    All

    I ve been reading some event examples and i ve added an example of some code below, my question is (being a total newbee i.e. day 1) what do I save this file as and where do I save it to make use of

    Sorry such a daft question but very new to this and keen to learn

     

    Gibbo

    using System;
    using umbraco.BusinessLogic;
    using umbraco.cms.presentation.Trees;
     
    namespace OnlyForAdmins
    {
       
    /// <summary>
       
    /// Makes a document invisible for writers
       
    /// </summary>
       
    public class MenuIsNotForWriters : ApplicationBase
       
    {
           
    /// <summary>
           
    /// Wire up the event handler
           
    /// </summary>
           
    public MenuIsNotForWriters()
           
    {
               
    BaseContentTree.AfterNodeRender += new BaseTree.AfterNodeRenderEventHandler(BaseContentTree_AfterNodeRender);
           
    }
     
           
    /// <summary>
           
    /// Removes node from menu tree if page is protected and the user is a writer
           
    /// </summary>
           
    void BaseContentTree_AfterNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e)
           
    {
               
    //check if page is protecetd and the usertype is writer
               
    if (node.IsProtected.GetValueOrDefault(false) && umbraco.helper.GetCurrentUmbracoUser().UserType.Alias == "writer")
               
    {
                   
    //Writers cannot see protected pages
                    sender
    .Remove(node);
               
    }
           
    }
       
    }
    }

     

  • Rodion Novoselov 694 posts 859 karma points
    Jan 22, 2012 @ 23:07
    Rodion Novoselov
    0

    The simplest way to add code to the site is to place it in a .cs file inside the "/App_Code" folder (you can name the file as you like but keep its extension ".cs"). Another option is to compile the file into a separate assembly and put it into the "/bin" folder.

    However, it seems that what you want to achieve is doable in much simpler way without coding by setting proper permissions to the content node (right click -> "Permissions").

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Jan 23, 2012 @ 06:50
    Jeroen Breuer
    0

    Rodion is right. You probably don't need events to do this. If you still want more info about events you can find it here:

    http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events

    http://www.richardsoeteman.net/2009/02/22/UmbracoV4EventsDemo.aspx

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft