public void ImportStandardCsv(TermStore oStore, string csvFile, Encoding encoding) { Group oGroup = oStore.Groups[TermStoreGroupName]; ImportManager manager = oStore.GetImportManager(); bool allAdded; string errorMessage; manager.ImportTermSet(oGroup, new StreamReader(csvFile, encoding), out allAdded, out errorMessage); }
public static void ImportCSV(string csvPath, string SiteURL) { SPSite oSite = new SPSite(SiteURL); SPWeb oWeb = oSite.OpenWeb(); string groupName = "TermSetGroupImport"; try { StreamReader reader = File.OpenText(csvPath); TaxonomySession session = new TaxonomySession(oSite); TermStore store = session.TermStores[0]; var exist = from t in store.Groups where t.Name == groupName select t; Group group; if (exist == null) { group = store.CreateGroup(groupName); } else { group = exist.FirstOrDefault(); } ImportManager manager = store.GetImportManager(); bool allTermsAdded = false; string errorMsg = string.Empty; manager.ImportTermSet(group, reader, out allTermsAdded, out errorMsg); if (errorMsg.Length > 0) { throw new Exception(errorMsg); } } catch (Exception ex) { Console.WriteLine(ex); } }