Blog Archives
Problem: User can’t see Managed metadata fields in SharePoint 2010
Posted by Rund
Some Problem cases:
1- Users can see managed metadata terms when setting properties for an Item, but when they press “view Item properties” they cant see them and when pressing “edit item properties” they can see them again!
2- Actions based on Managed metadata fields does not work out for regular users but work out perfectly when workflow is started by the system account.
3- any other problem regards managed metadata where regular users can’t handle them but System account can.
As the problem is only on regular users its clearly a permissions problem.
Solution:
Go to http://ServerName:Port/Sites/SiteName/Lists/TaxonomyHiddenList/
You will see a regular SharePoint list with the terms as items in it.
Go to list permissions from the ribbon, and give the permission level “read” for all authenticated users on your system.
That’s it, this supposedly can fix your problem.
Set Managed Metadata Fields value Programmatically in SharePoint 2010
Posted by Rund
Managed metadata fields in SharePoint 2010 are very special, their value can’t be simply set by one line of code or one action in a workflow like a text or number filed, so we will be coding a tiny event receiver to set a managed metadata field value.
My Case is I needed to set the field value as static one based on the library that a user uploads the document to in order to handle human errors in choosing the term when adding the document metadata,
1- Open your Visual Studio, Start a new SharePoint Project and choose event receiver.
2- Choose the type of your list and the type of the event receiver which will be “Item added”.
3- Make sure your project Application target framework is 3.5
4- Insert a dll reference “Microsoft.SharePoint” and “Microsoft.SharePoint.Taxonomy”
5- add using Microsoft.SharePoint and Microsoft.SharePoint.Taxonomy at the beginning of your Project.
6- Lets code:
public override void ItemAdded(SPItemEventProperties properties)
{
//Get site and list we are working on
SPSite CurrentSite = properties.OpenSite();
SPList TargetList = properties.List;
//Get the taxonomy field we want to insert to.
TaxonomyField EditField = (TaxonomyField)properties.ListItem.Fields[“Name Of Your Taxonomy Field“];
//Start a taxonomy session
TaxonomySession taxonomySession = new TaxonomySession(CurrentSite);
TermStore Store = taxonomySession.TermStores[“Your Taxonomy Service Name“];
Group group = Store.Groups[“Group Name“];
TermSet termSet = group.TermSets[“Term Set Name“];
//you can get the guid of the target term by going to http://servername/sites/siteName/ Lists/TaxonomyHiddenList and view the term properties.
string TermGuid = “Guid of the term you want to insert”;
// guid will look like: xxxx-yyyy-zzz-… etc.
Guid TermID = new Guid(TermGuid);
Term ToAddTerm = termSet.GetTerm(TermID);
//If your list has more than a content type and you need the code to run on a specific one only
if (properties.ListItem.ContentType == properties.List.ContentTypes[“Name Of Target Content Type“])
{
EventFiringEnabled = false;
EditField.SetFieldValue(properties.ListItem, ToAddTerm);
//In order for the user not to get the error message that the document already been updated on upload.
properties.ListItem.SystemUpdate(false);
EventFiringEnabled = true;
}
base.ItemAdded(properties);
}
}
}
7- That’s it, deploy and run your application.
Posted in C#, Code, Community, English, Learn SharePoint, Microsoft, MVP, PSUG, SharePoint 2010, SharePoint Services, Uncategorized
Tags: C#, field, Managed metadata, set field value, SharePoint 2010, taxonomy