Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am using this to upload documents to sharepoint library. Is it possible to update managed metadata type columns after adding files to document library. if yes, how.

I am using SP 2010 and powershell

$siteUrl = "http://sharepoint/"
$listName = "Site Assets"

$fileName = "OfferApp.xap"
$filePath = "OfferApp.Web\ClientBin\" + $fileName

[system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")
$site = New-Object Microsoft.SharePoint.SPSite($siteUrl)
$web = $site.OpenWeb()

$list = $web.Lists[$listName]

$fileCollection = $list.RootFolder.Files

$file = Get-Item $filePath
$stream = $file.OpenRead()
$spListItem = $fileCollection.Add($file.Name, $stream, $TRUE)

$spListItem["Managed-metadata type column 1"] = "Second Item"
$spListItem["Managed metadata type column 2"] = "My Text for second item"

"Uploaded " + $file.Name
if ($stream) {$stream.Dispose()}    

if ($web) {$web.Dispose()}
if ($site) {$site.Dispose()}
share|improve this question
    
This blog is somewhat close blogs.msdn.com/b/kaevans/archive/2012/02/15/… but still lacking what I need to do. I am supplying value from a csv file. so this wont work. $term = $terms | ?{$_.Name -eq "Newsfeed"} –  Mitch Veeno Jun 22 '12 at 4:18
    
The link you mentioned is doing exactly what you are looking for. Replacing "Newsfeed" with your value from csv should do the job. –  sssreddy Jun 22 '12 at 4:47
add comment

1 Answer

I take it that it is the metadata retrieval part that is the problem? First you have to add the file, call update() and then cast the item as necessary. The following code deals exclusively with the retrieval of a metadata term based on an identical text from a csv (or whatever) and assumes you already have a spWeb object instantiated called $web and the exact string of the MMS term coming out of the CSV and held in $valueFromCSV

#Setup TermStore objects
$tSession = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($web.Site)
$tStore = $tSession.TermStores["Managed Metadata Application"]
$tGroup = $tStore.Groups["Group Name"]
$tSet = $tGroup.TermSets["Term Set Name"]

#Termset <> collection of term objects, therefore:

#Get List of terms
$tSetList = $tSetSpecifics.GetAllTerms()
$tTerm = $tSetList | ?{$_.Name -eq $valueFromCSV}

Hope this helps. Had me tripped up for a long time.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.