Copied to clipboard

Flag this post as spam?

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


  • John Walker 43 posts 66 karma points
    Jan 14, 2011 @ 13:54
    John Walker
    0

    Document path from a document id (v4.5)

    Hello,

    Have a current issue where we need to check permissions of a node in the tree (uForum) we have the node Id. We know that umbraco.library.hasaccess exists but this requires a path parameter.

    Our current work around attempts to generate the path and then call the above function, code shown below.

            private static page GetPage(int docId)
    {


    var nodeFromId = umbraco.library.GetXmlNodeById(docId.ToString());


    if (nodeFromId != null)
    {
    var CurrentxmlNode = (System.Xml.IHasXmlNode)nodeFromId.Current;

    if (CurrentxmlNode != null)
    {
    var node = CurrentxmlNode.GetNode();
    if (node != null)
    return new page(node);
    }
    }


    return null;
    }

    public static string GetPath(int docId)
    {
    var p = GetPage(docId);
    List<string> ids = new List<string>();
    ids.Add(p.PageID.ToString());

    try
    {
    while (p != null && p.ParentId > 0)
    {
    p = GetPage(p.ParentId);
    if(p != null)
    ids.Add(p.PageID.ToString());
    }
    }
    catch { }

    ids.Add("-1");

    return string.Join(",", ids.Reverse<string>().ToArray());
    }

    This is currenty failing for a Uforum node on the snippet below.

     return new page(node);

    Any help would be appreciated.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jan 14, 2011 @ 14:08
    Dirk De Grave
    0

    If you're working with published content (I'm assuming you do), you'd better use 

    var node = new umbraco.presentation.nodeFactory.Node(id);
    var path = node.Path;

    and from there, use HasAccess as you'd normally do.

     

    Cheers,

    /Dirk

Please Sign in or register to post replies

Write your reply to:

Draft