Skip to main content

Taxonomy Export in SharePoint 2010

find the below code is helpful for taxonomy export


public class SimpleCSVExport
{
public string ExportTermSet(string GroupName, string TermSetName)
{
StringBuilder exportData = new StringBuilder();
exportData.AppendLine("\"Term Set Name\",\"Term Set Description\",\"LCID\",\"Available for Tagging\",\"Term Description\",\"Level 1 Term\",\"Level 2 Term\",\"Level 3 Term\",\"Level 4 Term\",\"Level 5 Term\",\"Level 6 Term\",\"Level 7 Term\"");
SPSite osite = new SPSite(siteUrl);
TaxonomySession session = new TaxonomySession(osite);
TermStore termStore = session.DefaultSiteCollectionTermStore;
Group group = termStore.Groups[GroupName];
TermSet termSet = group.TermSets[TermSetName];

foreach (var topTerm in termSet.Terms)
{
exportData.AppendLine(String.Format("\"{0}\",\"{1}\",,{2},\"{3}\",\"{4}\",,,,,,,", termSet.Name, termSet.Description, termSet.IsAvailableForTagging, topTerm.GetDescription(), topTerm.Name));

foreach (var childTerm in topTerm.Terms)
ExportTerm(exportData, childTerm, String.Format("\"{0}\"", topTerm.Name));
}

return exportData.ToString();
}

private void ExportTerm(StringBuilder exportData, Term term, string heritage)
{
heritage = String.Concat(heritage, ",", String.Format("\"{0}\"", term.Name));

exportData.AppendLine(String.Format(",,,{0},\"{1}\",{2}", term.IsAvailableForTagging, term.GetDescription(), heritage));

foreach (var subTerm in term.Terms)
ExportTerm(exportData, subTerm, heritage);
}
}

Comments

Popular posts from this blog

SharePoint Game Webpart

http://spgameoflifewebpart.codeplex.com/ Goal: The Game of Life web part was created for a talk I presented at SharePoint Saturday New York in 2009. At the time, SharePoint 2010 was still in Beta and most people hadn't see the Enterprise Metadata Management (taxonomy) features. I used the Game of Life web part as an introduction to the new taxonomy API. I offered to provide the code, so here it is. Requirements ----------------------- - SharePoint Server 2010 with Enterprise Features - Visual Studio 2010 (inc. SharePoint tools) Setup ----------------------- 1. Add your account as a Term Store Administrator. This right is independent to Site Collection Administrator or Farm Administrator status. To open the Term Store Management Tool go to Site Actions > Site Settings > Site Administartion > Term Store Management. You can also  open the same interface from Central Administration > Manage Service Applications > Managed Metadata Service. 2. Run the sol...

CAML Query Helper Class

http://sharepointcamlhelper.codeplex.com/ https://camldotnet.svn.codeplex.com/svn/JohnHolliday.Caml.Net/CAML.cs CAMLManager mgr = new CAMLManager(); mgr.QueryGroups.Add(new QueryGroup("Title", Types.FieldTypes.Text, Types.QueryTypes.Eq, "A Title")); mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.Or, "Title", Types.FieldTypes.Text, Types.QueryTypes.Eq, "Another Title")); mgr.QueryGroups.Add(new QueryGroup(Types.JoinTypes.And, QueryGroup.MergeTypes.Contain, "Total", Types.FieldTypes.Number, Types.QueryTypes.Geq, "2")); string caml = mgr.GetCAML(); Will provide the following: <Where>   <And>     <Or>       <Eq>         <FieldRef Name="Title" /><Value Type="Text">A Title</Value>       </Eq>       <Eq>         <FieldRef Name="Title" /><Value Type="Text">Another Title</Value>     ...

Globally Reusable Workflow in SharePoint 2010

http://www.codeproject.com/KB/sharepoint/ReusableWFsSharePoint2010.aspx http://www.khamis.net/blog/Lists/Posts/Post.aspx?ID=18 Video: Publish globally reusable workflows in SharePoint Designer 2010