Let's say I have a following taxonomy tree:

|    |-Frankfurt
|    |-Berlin

My library documents are attributed with a column Location which uses this taxonomy tree.
It's simple to create a list view filter to show documents attributed only with Berlin or Lyon.
How is it possible to create a filter which would show only documents related to Germany (by which I mean Berlin or Frankurt etc.), or other taxonomy non-leaf node?

  • do you mean Microsoft.Office.Server.WebControls.MetaDataNavTree ? – guyuming Aug 18 '17 at 2:33

You could programmatically create n views that would filter the list for the specific terms with the term has the view name.

If the number of locations is not so huge and rarely updated, I would create a small PowerShell script that would do the job proactively, otherwise, I would suggest creating a timer job that check for missing view based on available location terms and create them on the fly (you'll have the benefit in that way that it will work in all environments regardless of the term guid).

Something like this (not checking if the list view exist, neither retrieving the site the timer job but you get the idea :

SPSite site = new SPSite("your-site-collection-url");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Documents"];
SPViewCollection allviews = list.Views;
string viewName = "Germany";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
string query = String.Format("<Where><Eq><FieldRef Name="LocationTaxonomyField' LookupId='TRUE' /><Value Type='Lookup'>{0}</Value></Eq></Where>", "{germany-term-id}");     
allviews.Add(viewName, viewFields, query, 100, true, false);

It is possible to accomplish with OOTB Metadata Navigation and Filtering Feature using Navigation hierarchies control.

Navigation hierarchies control allows to select an item in a hierarchy for a managed metadata column with filter for

  • single Term

  • Term with descendant child terms

enter image description here enter image description here

Applying filter in Navigation hierarchies control corresponds to initializing filters for XslListViewWebPart which in turn generates query (CAML Where element to be more precise ) for current View (actually the same way as filtering works in SharePoint Designer).

In our cases, the following queries will be generated:

CAML Where clause for filter Term with descendant child terms

        <FieldRef Name="LocationTaxFieldName" LookupId="TRUE" />
            <Value Type="Integer">WssIdsOfGermanyTerm</Value>
            <Value Type="Integer">WssIdsOfBerlinTerm</Value>
            <Value Type="Integer">WssIdsOfFrankfurtTerm</Value>

CAML Where clause for filter single Term

            <FieldRef Name="LocationTaxFieldName" LookupId="TRUE" />
                <Value Type="Integer">WssIdsOfGermanyTerm</Value>

For more information about querying on Managed Metadata Field Values in SharePoint Server 2010 see MSDN

So, it is possible to create view (declaratively or programmatically) with such a filters.

  • I'm aware of this feature, however the question is, is there any way to remember such choice and associate it with a view? I mean any way, GUI or CAML. – soliloquyy Dec 31 '12 at 11:51
  • soliloquyy, answer has been updated with information about generated CAML for filters. – Vadim Gremyachev Jan 2 '13 at 14:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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