Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
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
10y
13.4
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"
Adding Attachments to a Specific Item in SharePoint
People also reading
Membership not found