Я пытаюсь загрузить файл в папку sharepoint с диска C моего P C. Но я получаю эту ошибку:
Исключение, вызывающее «UploadFile» с аргументом «3»: «Удаленный сервер возвратил ошибку: (403) Запрещено». В C: \ Users \ Projects \ file_upload.ps1: 18 char: 1 + $ webclient.UploadFile ($ destination + '/' + $ File.Name, 'PUT', $ File.Full ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo: NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId: WebException
Код это:
Add-Type -path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll'
Add-Type -path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
# Set the variables
$destination ='https://link to sharepoint site/foldername/'
$File =get-childitem 'C:\Users\path of the file in C drive'
# Since we’re doing this remotely, we need to authenticate
$securePasssword = ConvertTo-SecureString 'Password' -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential ('Username', $securePasssword)
# Upload the file
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = $credentials
$webclient.UploadFile($destination +'/'+ $File.Name,'PUT', $File.FullName)
Если бы вы могли помочь мне исправить этот код или предложить любой другой код, который будет работать, это было бы очень полезно.