C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Adding Attachments to a Specific Item in SharePoint
WhatsApp
Manpreet Singh
11y
13.5
k
0
0
25
Blog
This is a major thing which is used in our day to day activities but also in our major Migration projects in which we need to move Dot Net applications to SharePoint.
Here is a PowerShell which will do that easily for you, Change the following details down in the script.
Open SharePoint 2010 Management Shell by going to Start >> All Programs >>SharePoint >>Microsoft SharePoint 2010 Products >> SharePoint 2010 Management Shell (Run as Administrator).
Run the following script.
[System.Reflection.Assembly]::LoadWithPartialName(
"Microsoft.SharePoint"
)
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"
People also reading
Membership not found