网格文件文件夹到共享点列表

时间:2020-06-16 13:42:14

标签: sharepoint office365

所以,我有一个疑问。我有一些pdf文件(大约2000个),要作为附件上传到共享点列表中。但是我不想将所有文件上传到一个项目中。在列表中,我有2000个相同的项目(文件的名称与这些项目的ID相同)。上传它们的正确方法是什么?有没有一种方法可以将文件与项目网格化(每个项目一个)?还是应该使用我不知道的其他功能?比如图书馆?

pdf list

2 个答案:

答案 0 :(得分:0)

嗨JoãoGuilherme Bezerra Alves,

您可以利用powershell,请参考以下步骤:

  1. 准备列表项

enter image description here

  1. 准备文件

enter image description here

  1. 在脚本下运行:

#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()    
}

参考文档:

答案 1 :(得分:0)

reddit的一位朋友也使用flow发布了一个解决方案。两者都确实很棒!谢谢男人!

https://i.imgur.com/EFcHAPW.png https://i.imgur.com/47hpLi5.png

信用:

https://www.reddit.com/r/sharepoint/comments/ha2j9v/mesh_files_folder_to_sharepoint_list/