Click here to close now.

Welcome!

Apache Authors: Carmen Gonzalez, Pat Romanski, Bob Gourley, Elizabeth White, Mark R. Hinkle

Blog Feed Post

How to: Get related terms for a SharePoint 2013 Hashtag

If you have been following my posts lately, you might have noticed I have been dissecting the inner workings of the Hashtag Profile page (HashTagProfile.aspx).  I started with using search to query hashtag data and then yesterday I posted on how to query for trending tags.  The last component of this page is how to get the related terms of the hashtag.  As a reminder of what this does, it allows you to associate terms in the term store with a hashtag.  Whenever that term is used, it gets associated with the hashtag.  You can see the related tags in the screenshot below.

RelatedTagsProfilePage

Figuring this out took a bit of digging.  Remember that hashtags are nothing but terms themselves.  Ultimately what I discovered is that each term in the term store has the ability to add associations.  Unfortunately, the method to access these associations is marked internal meaning we can’t access it.  Luckily, I found that this really just gets stored in a custom property of the term.  Let’s take a look at what you need to do.

For simplicity, I used the server-side object model using a console application.  It should be possible to do this with JavaScript too though.  I suspect you can access the same information using SP.Taxonomy.Term.localCustomProperties.

Start by adding references for the following:

  • Microsoft.SharePoint.dll
  • Microsoft.SharePoint.Taxonomy.dll

In our class itself, we’ll need the following namespaces.

using Microsoft.SharePoint;

using Microsoft.SharePoint.Taxonomy;

I am going to get access to the term store in my case using an SPSite object for any given site collection on the site.

using (SPSite siteCollection = new SPSite("http://server/sitecollection"))

Inside, the using block, I get a TaxonomySession and TermStore object.

TaxonomySession taxonomySession = new TaxonomySession(siteCollection);

TermStore termStore = taxonomySession.DefaultKeywordsTermStore;

Now we need to get access to the term in the hashtag.  You can get this in a variety of ways but I am simply going to use the GUID which I took from the URL of the HashTagProfile.aspx page. Otherwise, you can access a Group object first and then find the term you are looking for that way.

RelatedTagsProfilePageUrl

Term

term = termStore.GetTerm(new Guid("cb9308fe-a187-4a3d-9e6a-657b06906f89")); To access the associated terms, we need to look in the CustomProperties collection with a value of _Sys_HashAssoc

string associatedTerms;

term.CustomProperties.TryGetValue("_Sys_HashAssoc", out associatedTerms);

This gives us a delimited string with the GUID of each associated term and the owner.  Here is what it looks like.

"973bdb1b-eb9f-4f8b-8512-6440b0913b4f||0#.w|sharepoint\\sp_setup||4c1ad4aa-77f6-40de-bd16-210cad44d0b3||0#.w|sharepoint\\sp_setup"

The delimiter to use is “||”.  Using string.Split() we can get the GUIDs we need and then look up the names of the terms.

string[] termGuidArray = associatedTerms.Split(new string[1] {"||"}, StringSplitOptions.None);

We are only interested in the terms, so we will loop through them with an increment of 2.

for (int i = 0; i < termGuidArray.Length; i += 2)

{

    Term associatedTerm = termStore.GetTerm(new Guid(termGuidArray[i]));

    Console.WriteLine("{0} ({1})", associatedTerm.Name, termGuidArray[i]);

}

Here we just use the GetTerm() method using the GUID we have parsed to print out the name of the term.

When the code executes, it looks like this.

RelatedTagsConsoleApplication

Here is what the entire code snippet looks like together.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

using Microsoft.SharePoint;

using Microsoft.SharePoint.Taxonomy;

 

namespace TaxonomyConsoleApplication

{

    class Program

    {

        static void Main(string[] args)

        {

            using (SPSite siteCollection = new SPSite("http://sp2010/sites/test"))

            {

                TaxonomySession taxonomySession = new TaxonomySession(siteCollection);

                TermStore termStore = taxonomySession.DefaultKeywordsTermStore;

                Term term = termStore.GetTerm(new Guid("cb9308fe-a187-4a3d-9e6a-657b06906f89"));

                string associatedTerms;

                term.CustomProperties.TryGetValue("_Sys_HashAssoc", out associatedTerms);

 

                string[] termGuidArray = associatedTerms.Split(new string[1] {"||"}, StringSplitOptions.None);

 

                for (int i = 0; i < termGuidArray.Length; i += 2)

                {

                    Term associatedTerm = termStore.GetTerm(new Guid(termGuidArray[i]));

                    Console.WriteLine("{0} ({1})", associatedTerm.Name, termGuidArray[i]);

                }

            }

 

            Console.ReadLine();

        }

    }

}

If you have been wanting to customize this functionality, I hope that you find today’s example useful.

Read the original blog entry...

More Stories By Corey Roth

Corey Roth, a SharePoint Server MVP, is a consultant at Hitachi Consulting specializing in SharePoint and Office 365 for clients in the energy sector. He has more than ten years of experience delivering solutions in the energy, travel, advertising and consumer electronics verticals.

Corey specializes in delivering ECM and search solutions to clients using SharePoint. Corey has always focused on rapid adoption of new Microsoft technologies including Visual Studio 2013, Office 365, and SharePoint.

He is a member of the .NET Mafia (www.dotnetmafia.com) where he blogs about the latest technology and SharePoint. He is dedicated to the community and speaks regularly at user groups and SharePoint Saturdays.

@ThingsExpo Stories
SYS-CON Events announced today that Windstream, a leading provider of advanced network and cloud communications, has been named “Silver Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9–11, 2015, at the Javits Center in New York, NY. Windstream (Nasdaq: WIN), a FORTUNE 500 and S&P 500 company, is a leading provider of advanced network communications, including cloud computing and managed services, to businesses nationwide. The company also offers broadband, phone and digital TV services to consumers primarily in rural areas.
SYS-CON Events announced today that Dyn, the worldwide leader in Internet Performance, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Dyn is a cloud-based Internet Performance company. Dyn helps companies monitor, control, and optimize online infrastructure for an exceptional end-user experience. Through a world-class network and unrivaled, objective intelligence into Internet conditions, Dyn ensures traffic gets delivered faster, safer, and more reliably than ever.
SYS-CON Events announced today that Open Data Centers (ODC), a carrier-neutral colocation provider, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. Open Data Centers is a carrier-neutral data center operator in New Jersey and New York City offering alternative connectivity options for carriers, service providers and enterprise customers.
SYS-CON Events announced today that On the Avenue Marketing Group, a sales and marketing firm that utilizes events to market and sell products to consumers, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. On the Avenue Marketing Group (OTA) is a sales and marketing firm that utilizes events to market and sell products to consumers. On behalf of our clients, we attend thousands of fairs, festivals, expos, concerts, conferences, and sporting events annually, helping them reach millions of individuals ...
SYS-CON Events announced today that ActiveState, the leading independent Cloud Foundry and Docker-based PaaS provider, has been named “Silver Sponsor” of SYS-CON's DevOps Summit New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. ActiveState believes that enterprises gain a competitive advantage when they are able to quickly create, deploy and efficiently manage software solutions that immediately create business value, but they face many challenges that prevent them from doing so. The Company is uniquely positioned to help address these challenges thro...
SYS-CON Events announced today that Vitria Technology, Inc. will exhibit at SYS-CON’s @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Vitria will showcase the company’s new IoT Analytics Platform through live demonstrations at booth #330. Vitria’s IoT Analytics Platform, fully integrated and powered by an operational intelligence engine, enables customers to rapidly build and operationalize advanced analytics to deliver timely business outcomes for use cases across the industrial, enterprise, and consumer segments.
SYS-CON Events announced today that Alert Logic, the leading provider of Security-as-a-Service solutions for the cloud, has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo® and DevOps Summit 2015 New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY, and the 17th International Cloud Expo® and DevOps Summit 2015 Silicon Valley, which will take place November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that kintone has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY, and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. kintone promotes cloud-based workgroup productivity, transparency and profitability with a seamless collaboration space, build your own business application (BYOA) platform, and workflow automation system.
SYS-CON Events announced today that Akana, formerly SOA Software, has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo® New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. Akana’s comprehensive suite of API Management, API Security, Integrated SOA Governance, and Cloud Integration solutions helps businesses accelerate digital transformation by securely extending their reach across multiple channels – mobile, cloud and Internet of Things. Akana enables enterprises to share data as APIs, connect and integrate applications, drive part...
SYS-CON Events announced today that CommVault has been named “Bronze Sponsor” of SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY, and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. A singular vision – a belief in a better way to address current and future data management needs – guides CommVault in the development of Singular Information Management® solutions for high-performance data protection, universal availability and sim...
SYS-CON Events announced today that SafeLogic has been named “Bag Sponsor” of SYS-CON's 16th International Cloud Expo® New York, which will take place June 9-11, 2015, at the Javits Center in New York City, NY. SafeLogic provides security products for applications in mobile and server/appliance environments. SafeLogic’s flagship product CryptoComply is a FIPS 140-2 validated cryptographic engine designed to secure data on servers, workstations, appliances, mobile devices, and in the Cloud.
SYS-CON Events announced today that StorPool Storage will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. StorPool is distributed storage software that allows service providers, enterprises and other cloud builders to run data storage on standard x86 servers, instead of using expensive and inefficient storage arrays (SAN).
SYS-CON Events announced today that Site24x7, the cloud infrastructure monitoring service, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Site24x7 is a cloud infrastructure monitoring service that helps monitor the uptime and performance of websites, online applications, servers, mobile websites and custom APIs. The monitoring is done from 50+ locations across the world and from various wireless carriers, thus providing a global perspective of the end-user experience. Site24x7 supports monitoring H...
SYS-CON Events announced today that B2Cloud, a provider of enterprise resource planning software, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. B2cloud develops the software you need. They have the ideal tools to help you work with your clients. B2Cloud’s main solutions include AGIS – ERP, CLOHC, AGIS – Invoice, and IZUM
SYS-CON Events announced today that Intelligent Systems Services will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Established in 1994, Intelligent Systems Services Inc. is located near Washington, DC, with representatives and partners nationwide. ISS’s well-established track record is based on the continuous pursuit of excellence in designing, implementing and supporting nationwide clients’ mission-critical systems. ISS has completed many successful projects in Healthcare, Commercial, Manufacturing, ...
SYS-CON Events announced today that Vicom Computer Services, Inc., a provider of technology and service solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. They are located at booth #427. Vicom Computer Services, Inc. is a progressive leader in the technology industry for over 30 years. Headquartered in the NY Metropolitan area. Vicom provides products and services based on today’s requirements around Unified Networks, Cloud Computing strategies, Virtualization around Software defined Data Ce...
SYS-CON Events announced today that Optimal Design, an Internet of Things solution provider, will exhibit at SYS-CON's Internet of @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Optimal Design is an award winning product development firm offering industrial design and engineering services to the consumer, medical, and defense markets.
SYS-CON Events announced today that Tufin, the market-leading provider of Security Policy Orchestration Solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. As the market leader of Security Policy Orchestration, Tufin automates and accelerates network configuration changes while maintaining security and compliance. Tufin's award-winning Orchestration Suite™ gives IT organizations the power and agility to enforce security policy across complex, multi-vendor enterprise networks. With more than 1...
SYS-CON Events announced today that MangoApps will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY., and the 17th International Cloud Expo®, which will take place on November 3–5, 2015, at the Santa Clara Convention Center in Santa Clara, CA. MangoApps provides private all-in-one social intranets allowing workers to securely collaborate from anywhere in the world and from any device. Social, mobile, and easy to use. MangoApps has been named a "Market Leader" by Ovum Research and a "Cool Vendor" by Gartner...
SYS-CON Events announced today that Cloudian, Inc., the leading provider of hybrid cloud storage solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Cloudian, Inc., is a Foster City, California - based software company specializing in cloud storage software. The main product is Cloudian, an Amazon S3-compliant cloud object storage platform, the bedrock of cloud computing systems, that enables cloud service providers and enterprises to build reliable, affordable and scalable cloud storage solu...