1

What is the SharePoint-hosted app permission that is required to create a file on Style Library within the hosted web?

I use the following permission but it is not working and the error is

Access denied. You do not have permission to perform this action or access this resource."

The strange thing about this permission it is allow me to create folders and items but not file!!!

  <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="Write" />

Note: I can’t use full control permission because I need to publish my app on Microsoft office store.

the following is my code and it is work with full control permission but not for write permission:

    var clientContext = new SP.ClientContext(hostContextWebUrl);
    var factory = new SP.ProxyWebRequestExecutorFactory(_spPageContextInfo.webAbsoluteUrl);
    clientContext.set_webRequestExecutorFactory(factory);
    var clientContextSite = new SP.AppContextSite(clientContext, hostContextWebUrl);
    fileCreateInfo = new SP.FileCreationInformation();
    fileCreateInfo.set_url(filename);
    fileCreateInfo.set_overwrite(true);
    fileCreateInfo.set_content(new SP.Base64EncodedByteArray());

    for (var i = 0, fileLength = contents.length ; i < fileLength; ++i) {
         fileCreateInfo.get_content().append(contents.charCodeAt(i));
    }

    var files = clientContextSite.get_web().getFolderByServerRelativeUrl(serverRelativeUrl).get_files();
    clientContext.load(files);
    files.add(fileCreateInfo);

    clientContext.executeQueryAsync(Function.createDelegate(this, function () {

    })
    , Function.createDelegate(this, function (sender, args) {

    }));
  • How are you creating the File? Can you please post relevant code/information? – Amal Hashim Jan 20 '15 at 15:42
  • Make sure the user who is running the app has Contribute permissions.Also try using "Manage". you can publish to sharepoint store with Manage permission. – Unnie Jan 21 '15 at 11:17
  • @Unnie I'm using admin user, and the Manage permission has the same issue – jobin Jan 21 '15 at 18:46
1

these is security limitation to add files to Style Library using Apps that has manage permission, you need full permission to do that.

anyway, you can create files on different libraries using manage permission.

1

Is this SharePoint Online? Could you check in your SharePoint Settings (SharePoint Admin > Settings) for a property called "Custom Script"?

If this is set to "Prevent users from running custom scripts..." then this may be the cause.

This is a recent addition to SharePoint Online and it is set to prevent by default. While it purports to be limited to personal sites and self-service sites, it also impacts the root site collection ("/") as well - presumably in error. As well as limiting custom scripting, it also prevents upload to the Master Page Gallery (and maybe Style Library?).

You can also check if this is the case by looking for the "Solution Gallery" link in site settings - if it is missing, then custom scripting is turned off.

Be warned, re-enabling the setting can take 24 hours to have an effect.

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.