【问题标题】:Mesh files folder to sharepoint list网格文件文件夹到共享点列表
【发布时间】:2020-10-06 03:33:14
【问题描述】:

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

pdf list

【问题讨论】:

    标签: sharepoint office365


    【解决方案1】:

    您好若昂·吉尔赫姆·贝泽拉·阿尔维斯,

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

    1. 准备列表项

    1. 准备文件

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

    参考文档:

    【讨论】:

      【解决方案2】:

      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/

      【讨论】:

        猜你喜欢
        • 2011-01-18
        • 2015-06-19
        • 1970-01-01
        • 2022-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多