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
Post a Comment