ค้นหาเว็บไซต์

อัปโหลดไฟล์ไปยัง SharePoint จากระยะไกลโดยใช้เว็บไคลเอ็นต์และ PowerShell


หากคุณต้องการอัปโหลดไฟล์ไปยังไลบรารีเอกสาร SharePoint จากฝั่งไคลเอ็นต์ (หรือจากระยะไกล) นี่คือข้อมูลโค้ด PowerShell ที่ดี

อัปโหลดไฟล์ไปยัง SharePoint โดยใช้ Web Client PowerShell:


#Variable for Source folder in Local machine & Destination in SharePoint
$Source ="c:\temp\file.pdf"
$Target="https://portal.crescent.com/projects/Documents/File.pdf"
 
#Create new web client object
$WebClient = new-object System.Net.WebClient
$Webclient.UseDefaultCredentials = $true

#upload file to sharepoint using webclient
$WebClient.UploadFile($Target,"PUT", $Source) 

อัปโหลดไฟล์ทั้งหมดในโฟลเดอร์ไปยัง SharePoint - วิธีการใส่ HTTP ของไคลเอ็นต์เว็บ:


#Variable for Source folder in Local machine
$FilesLocation ="D:\Scripts\Reports\"
$TargetLocation="https://Operations.Crescent.com/Reports/"

#Create new web client object
$WebClient = new-object System.Net.WebClient
$WebClient.Credentials = [System.Net.CredentialCache]::DefaultCredentials

#Use these lines if you use different credentials
#$cred = new-object System.Net.NetworkCredential("USER NAME","PASSWORD","DOMAIN")
#$WebClient.credentials = $cred

#Target File Location to upload
function Set-DestinationFile($FileName)
{ 
   $TargetLocation + $(split-path -leaf $FileName)
}

#Iterate through each file and upload
Get-ChildItem $FilesLocation | ForEach-Object {

  $DestinationFile= Set-DestinationFile $_;

  #upload file to sharepoint using webclient
  $WebClient.UploadFile($DestinationFile,"PUT", $_.FullName)
} 

บทความที่เกี่ยวข้อง