所以我有个疑问。我有一些pdf文件(大约2000年左右),我想上传作为附件在sharepoint列表。但我不想把所有的文件都上传到一个项目中。在列表中,我有相同的2000项(文件的命名与项目的ID相同)。上传它们的正确方法是什么?有一种方法可以将文件与项目(每项一项)进行网格化?还是我应该使用另一个我不知道的特性?比如图书馆?
发布于 2020-06-17 06:40:14
你好Jo Bezerra Alves,
您可以利用powershell,请参考以下步骤:


#Set Variables
$SiteURL = "https://{tenant}.sharepoint.com/sites/abc"
$ListName = "yourlistname"
$Username='abc@xxx.onmicrosoft.com'
$Password = '***'
#region Credentials
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass)
#endregion Credentials
#Connect to PNP Online
Connect-PnPOnline -Url $SiteURL -Credentials $PSCredentials
$Folderpath ="D:\mypdffolder"
ForEach ($File in (Get-ChildItem $FolderPath -File))
{
# try to find the corresponding item (has the same id)
$caml= @"
<View>
<Query>
<Where>
<Eq>
<FieldRef Name='Title' />
<Value Type='Text'>$($File.Name)</Value>
</Eq>
</Where>
</Query>
</View>
"@
$Items = Get-PnPListItem -List $ListName -Query $caml
if($Items -eq $null){
Write-Host "Do not find such an item that has the same id: $($File.Name)"
Continue
}
if($Items -is [system.array]){
$Item = $Items[0]
}else{
$Item = $Items
}
$AttachmentInfo = New-Object -TypeName Microsoft.SharePoint.Client.AttachmentCreationInformation
$AttachmentInfo.FileName = $File.Name
$AttachmentInfo.ContentStream = $File.OpenRead()
$AttchedFile = $Item.AttachmentFiles.Add($AttachmentInfo)
Invoke-PnPQuery
$AttachmentInfo.ContentStream.Close()
}
参考文件:
发布于 2020-06-18 09:20:43
reddit的一位朋友也发布了一个使用flow的解决方案。都在哪里真的很好!谢谢,伙计!
https://i.imgur.com/EFcHAPW.png https://i.imgur.com/47hpLi5.png
致谢:
https://stackoverflow.com/questions/62409958
复制相似问题