Open yzdoe opened 4 years ago
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
The way Add-PnPFile is implemented requires to iterate over the RootFolders of the Siteto find the one specified in the -Folder parameter. What permissions does the user have at Site level ? Could you try granting incremental permissions (Read, Contribute, etc) at Site level ?
At site level, the user has 'Edit, Limited Access'.
Since the user has 'Edit' permission already, I don't know what other permission than 'Full Control' I can try. I know 'Full Control' at site level will work, but that seems too much for just copying files to one specific document library. I want to find the minimum permission level for using add-pnpfile to one specific document library.
OK, I checked what 'Edit' permission means: the following is what I got. So for 'List Permissions' (I think that's the only section relevant), only 'Override List Behaviors' and 'Approve items' are missing.
Also, even though the user can not use 'add-pnpfile' to copy a file but they can use web browser to upload a file to the document library. Shouldn't the two ways be consistent? If a user can upload a file through web browser, they should be add a file through add-pnpfile?
One possible workaround until this issue is fixed is to get the folder with
$folder = Get-PnPFolder $libraryName
of type Microsoft.SharePoint.Client.Folder and then use CSOM to upload the file.
I created a PR at https://github.com/SharePoint/PnP-PowerShell/pull/2478 . It's definitely not perfect as it still throws an "Access Denied" error if the specified Subfolder in the Library doesn't exist, but at least files get uploaded without any error using your How To Reproduce steps.
Thanks, subfolder is not an issue, user can create subfolders without problem in existing document library as long as they have edit permission. They can't create document library, the top folder, without proper site wide permission, but that's expected.
@jackpoz Don't know why your PR 2478 didn't get this "status:checked and ready for merge" sticker. A couple of newer PRs got that already. Looks like it won't be in the next release?
It takes time to review and merge PRs, maybe it will be in next or the one after.
Did you have time to test locally that PR ? Did it fix the issue/improve it ?
This is a work related issue and I don't have Visual Studio compiler at work. I will find out if there is any free compiler so that I can test.
@jackpoz I merged recent dev version of this repository to your pull request branch, and it works fine.
Glad to hear :) maybe write your feedback in the PR too, it will help the PnP team decide when to merge it :)
Commented under the pull request. Thanks for the fix.
Reporting an Issue or Missing Feature
Issue
Expected behavior
Add-PnpFile should successfully upload file to the specified folder
Actual behavior
Only if a user is an owner of the site add-pnpfile works. Even though the user is given full control to the document library.
Steps to reproduce behavior
Connect-PnPOnline -Url 'the_sharepoint_url' Add-PnPFile -Path test.txt -Folder 'the_document_library'
Which version of the PnP-PowerShell Cmdlets are you using?
What is the version of the Cmdlet module you are running?
3.17.20
How did you install the PnP-PowerShell Cmdlets?
one user who is an owner of the site, pnp-addfile works, the owner's permission on the document library is as follows:
the other user who has identical permission on the document library got permission denied when using add-pnpfile: