Checking access rights when presenting Link Collection

Per Nergård
Member since: 2007

I'm using a Link Collection property and have made  a usercontrol that adds custom rendering of the links.

One thing I wan't to do is display a "Secure file icon" if a document resides in a folder that "Everyone" doesn't have read access to.

 I tried doing this with

UnifiedPathInfo pathInfo = new UnifiedPathInfo(path);
AccessControlList acl = pathInfo.Access;
return acl.QueryDistinctAccess(AccessLevel.Read);

But it didn'w work. How can I accomplish this?

Per N

#26384 Dec 03, 2008 11:21
  • Per Nergård
    Member since: 2007
    as input to the above code I set the path variable to linkitem.href;
    #26385 Dec 03, 2008 11:33

    dont know if this works but try:

    return pathInfo.Access.Exists("Everyone")

     -Kjetil Simensen

    #26386 Dec 03, 2008 11:36
  • Per Nergård
    Member since: 2007

    It didn't work.

    I tried the below code. If i try to get a file in a folder where everyone has no access I get an exception. That works for a anonymous user. But as soon as I log in I dont get the exception.

     I want to always display the icon if the group Everyone has no access.

    // UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(path) as UnifiedFile;

    // AccessLevel l = file.QueryAccess();


    //catch (UnauthorizedAccessException ex)

    // return false;


    #26395 Dec 03, 2008 17:20
  • Anders Hattestad
    Member since: 1996


    Its the Directory in the filesystem that has access right.

    In CMS 5 if you want to check if all users have acces to a file you can use this code 

    file.Parent.ACL.QueryDistinctAccess(PrincipalInfo.AnonymousPrincipal, AccessLevel.Read)


    #26396 Dec 03, 2008 21:28
  • Per Nergård
    Member since: 2007

    Thank you for the answer Anders I figured it out last night. It's also possible to do the below to check the the directotry directly without trying to access the file.

    UnifiedDirectory dir = HostingEnvironment.VirtualPathProvider.GetDirectory(path) as UnifiedDirectory.



    #26397 Dec 04, 2008 8:19