0

I'm working with SharePoint Client API 2010 for a .Net application. I want to check if the current user (or a specified user) can read a specified File? This user could also be in a SP Group or in a LDAP Group.

My current approach would be to request the file and wait for an exception that may be raised if a user doesnt have the required permission:

        string SiteUrl = "https://myintraneturl/";
        ClientContext clientContextSP = new ClientContext(SiteUrl);
        Web site = clientContextSP.Web;

        File file = site.GetFileByServerRelativeUrl("/someworkingfilepath/somefile.txt");


        var listItem = file.ListItemAllFields;
        clientContextSP.Load(listItem, items => items.EffectiveBasePermissions);

        try {

        clientContextSP.ExecuteQuery();

        var test = listItem.EffectiveBasePermissions.Has(PermissionKind.Open);

        } catch...

This approach doesnt seem to be right to me. I would control the program flow by exception and that is not what seems to be desirable.

Do you have some suggestions?

0

I have found a solution with:

    public bool DoesUserHavePermission(string RelativeUrl)
    {
        File file = clientContext.Web.GetFileByServerRelativeUrl(RelativeUrl);
        clientContext.Load(file, item => item.Exists);
        clientContext.ExecuteQuery();

        return file.Exists;
    }

It's return false when the file doesn't exists but also when the current user doesn't have the permission to see this file !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.