首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“网格文件”文件夹到sharepoint列表

“网格文件”文件夹到sharepoint列表
EN

Stack Overflow用户
提问于 2020-06-16 13:42:14
回答 2查看 39关注 0票数 0

所以我有个疑问。我有一些pdf文件(大约2000年左右),我想上传作为附件在sharepoint列表。但我不想把所有的文件都上传到一个项目中。在列表中,我有相同的2000项(文件的命名与项目的ID相同)。上传它们的正确方法是什么?有一种方法可以将文件与项目(每项一项)进行网格化?还是我应该使用另一个我不知道的特性?比如图书馆?

pdf列表

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-17 06:40:14

你好Jo Bezerra Alves,

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

  1. 准备清单项目

  1. 准备文件

  1. 运行以下脚本:

代码语言:javascript
复制
#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()    
}

参考文件:

票数 0
EN

Stack Overflow用户

发布于 2020-06-18 09:20:43

reddit的一位朋友也发布了一个使用flow的解决方案。都在哪里真的很好!谢谢,伙计!

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

致谢:

名单/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62409958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档