当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 使用 PowerShell 将附件添加到 SharePoint 中的列表项

作者:精品下载站 日期:2024-12-14 14:06:00 浏览:14 分类:玩电脑

使用 PowerShell 将附件添加到 SharePoint 中的列表项


如何向 SharePoint 列表项添加附件?

在 SharePoint 中,您可以向列表项添加附件以提供更多信息或补充列表中的数据。附加文件可以是文档、图像或其他类型的文件。在本文中,我们将向您展示如何向列表项添加附件。

要将附件添加到 SharePoint 列表项,请执行以下操作:

  • 导航至列表,打开您要添加附件的列表项
  • 单击功能区“项目”选项卡中的“附加文件”按钮。
  • 浏览并选择要附加的文件。单击“确定”将文件附加到项目。您还可以编辑列表项,然后附加文件。

    [玩转系统] 使用 PowerShell 将附件添加到 SharePoint 中的列表项

PowerShell 将附件添加到 SharePoint 列表项

以下是用于以编程方式在 SharePoint 中添加附件以列出项目的 PowerShell 脚本:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom Function to Add attachment to SharePoint List Item
Function Add-Attachment($Item, $AttachmentPath)
{
  $FileContent = [System.IO.File]::ReadAllBytes($AttachmentPath)
  $Item.Attachments.Add([System.IO.Path]::GetFileName($AttachmentPath), $FileContent)
  $Item.Update()
 
  Write-host "Attachment Added to List Item Successfully!"
}

#Variables
$SiteURL="https://portal.crescent.com/sites/Deals"
$ListName="Tasks"
$ItemID=1
$AttachmentPath="c:\Scripts\ASI-LOG.docx"

$web = Get-SPWeb $SiteURL
$List = $web.Lists[$ListName]
$Item = $list.GetItemById($ItemID)

#Call the function to Add Attachment
Add-Attachment $Item $AttachmentPath

若要将附件添加到 SharePoint Online 列表项,请使用:SharePoint Online:使用 PowerShell 将附件添加到列表项

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯