Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
improved formatting
Source Link
Asad Refai
  • 6.1k
  • 8
  • 36
  • 57

I have tried this code to attach a document in custom list for sharepoint online, but it is not working.

$site = [Microsoft.SharePoint.SPSite]("Your site name")
$web = $site.OpenWeb()
$list = $web.Lists["Your List name"]
$item = $list.GetItemById(Your Id)
AddAttachment $item "Your Document Name"

function AddAttachment($item, $filePath)
{
$bytes = [System.IO.File]::ReadAllBytes($filePath)
$item.Attachments.Add([System.IO.Path]::GetFileName($filePath),$bytes)
$item.Update()
}

$site = [Microsoft.SharePoint.SPSite]("Your site name") $web = $site.OpenWeb() $list = $web.Lists["Your List name"] $item = $list.GetItemById(Your Id) AddAttachment $item "Your Document Name" function AddAttachment($item, $filePath) { $bytes = [System.IO.File]::ReadAllBytes($filePath) $item.Attachments.Add([System.IO.Path]::GetFileName($filePath),$bytes) $item.Update() } 

I have tried this code but it is not working.

$site = [Microsoft.SharePoint.SPSite]("Your site name")
$web = $site.OpenWeb()
$list = $web.Lists["Your List name"]
$item = $list.GetItemById(Your Id)
AddAttachment $item "Your Document Name"

function AddAttachment($item, $filePath)
{
$bytes = [System.IO.File]::ReadAllBytes($filePath)
$item.Attachments.Add([System.IO.Path]::GetFileName($filePath),$bytes)
$item.Update()
}

I have tried this code to attach a document in custom list for sharepoint online, but it is not working.

$site = [Microsoft.SharePoint.SPSite]("Your site name") $web = $site.OpenWeb() $list = $web.Lists["Your List name"] $item = $list.GetItemById(Your Id) AddAttachment $item "Your Document Name" function AddAttachment($item, $filePath) { $bytes = [System.IO.File]::ReadAllBytes($filePath) $item.Attachments.Add([System.IO.Path]::GetFileName($filePath),$bytes) $item.Update() } 
Source Link
Ravi
  • 856
  • 5
  • 23

how to attach document in custom list for sharepoint online using Powershell?

I have tried this code but it is not working.

$site = [Microsoft.SharePoint.SPSite]("Your site name")
$web = $site.OpenWeb()
$list = $web.Lists["Your List name"]
$item = $list.GetItemById(Your Id)
AddAttachment $item "Your Document Name"

function AddAttachment($item, $filePath)
{
$bytes = [System.IO.File]::ReadAllBytes($filePath)
$item.Attachments.Add([System.IO.Path]::GetFileName($filePath),$bytes)
$item.Update()
}