The most robust way of keeping your SharePoint manageable is to keep it's structure clean and clear, though business often introduces some complex rules and convoluted workflows. Degree of complexity even increases when it comes to governance and security.
One task of such kind that business demands is to secure document based on the metadata values. In SharePoint 2007 it usually leads to custom development or purchasing one of the 3rd party products (like one from the Titus Labs), luckily SharePoint 2010 came up to help. Let's say we were asked to assign custom permission level on the document based on it's category, although to make it harder assume that document can have multiple categories.
The following picture shows security matrix to be implemented:
Here are the steps to achieve this using out-of-the-box Content Organizer feature, folder based security structure and Metadata Navigation.
1. Create "MD Document" content type
2. Add Managed Metadata column "Document Category" to the content type with the following Taxonomy
3. Add MD Document content type to a "Documents" document library.
4. Create three folders in a document library "Public", "Confidental", "Top Secret". Break permissions inheritance on these folder and assign desired permissions in accordance with security matrix.
5. Go to site settings and activate Content Organizer feature.
6. Add content organizer rule to route documents having Accounting category to a Top Secret folder.
7. Create rules for all category types. Less privileged category should have higher rule priority.
Starting from that point all documents that a user uploads to a Documents library will be processed by Content Organizer and placed in a secured folder based on a document category, i.e. secured based on the metadata.
A user will be informed by the following message in the upload document dialog:
And when category field is set up, document will be automatically routed:
Also, I like to use Metadata Navigation and Filtering feature in order to make navigation over categories more convenient. Activate this feature in Site Settings, go to document document library settings, then Metadata Navigation Settings and add Document Category column to the Selected Hierarchy fields. That will add a nice looking category tree to a documents list.
Showing posts with label Taxonomy. Show all posts
Showing posts with label Taxonomy. Show all posts
Saturday, January 29, 2011
Saturday, August 21, 2010
How to set managed metadata field value through code
Recently one of our clients reported an issue that setting taxonomy field value through code doesn't update the field value.
We noticed interesting fact, that even though value is stored in a field, UI control still shows an old value. After spending some time in a reflector digging in Microsoft.SharePoint.Taxonomy.dll we found out a way how SharePoint stores managed metadata and enterprise keywords values.
Guys from Microsoft use pretty simple approach, they store technical information in a hidden field created with the following algorithm.
Where str and str2 are DisplayName and InternalName of a hidden field respectively.
So, in order to set taxonomy field value, either Managed Meatadata or Enterprise Keywords field, we used this piece of code:
GetHTField method is shown below:
This code was used in a code behind of a layout page with FormComponent control thus we were able to get current item from SPContext.
In the next post, for those who are not able to use values from SPContext's current item, I will tell about format of a taxonomy hidden field value and show how to calculate it manually.
We noticed interesting fact, that even though value is stored in a field, UI control still shows an old value. After spending some time in a reflector digging in Microsoft.SharePoint.Taxonomy.dll we found out a way how SharePoint stores managed metadata and enterprise keywords values.
Guys from Microsoft use pretty simple approach, they store technical information in a hidden field created with the following algorithm.
string str; string str2; int num = 0; while (fields.ContainsField(base.Title + "_" + num.ToString(CultureInfo.InvariantCulture))) { num++; } if (this.IsKeyword) { str = "TaxKeywordTaxHTField"; str2 = "TaxKeywordTaxHTField"; } else { str = base.Title + "_" + num.ToString(CultureInfo.InvariantCulture); str2 = base.InternalName + "TaxHTField" + num.ToString(CultureInfo.InvariantCulture); }
Where str and str2 are DisplayName and InternalName of a hidden field respectively.
So, in order to set taxonomy field value, either Managed Meatadata or Enterprise Keywords field, we used this piece of code:
var currentItem = SPContext.Current.Item; // set field value item[fieldName] = currentItem[fieldName]; // find hidden field and set it's value SPField htField = GetHTField(item, fieldName); item[htField.StaticName] = currentItem[htField.StaticName];
GetHTField method is shown below:
private SPField GetHTField(SPItem item, string fieldName) { foreach (SPField field in item.Fields) { if (field.StaticName.StartsWith(fieldName) && field.StaticName.Contains("TaxHTField")) { return field; } } return null; }
This code was used in a code behind of a layout page with FormComponent control thus we were able to get current item from SPContext.
In the next post, for those who are not able to use values from SPContext's current item, I will tell about format of a taxonomy hidden field value and show how to calculate it manually.
Subscribe to:
Posts (Atom)