TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Adding Attachments to a Specific Item in SharePoint
Manpreet Singh
Jul 14, 2014
13.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
This blog defines how to add attachments to a specific item in SharePoint.
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
Next Recommended Reading
Add an attachment to the SharePoint 2010 list item using web service in powershell