Exemple #1
0
        private static void ExportTerms(string directoryPath, string groupName, string termsetName, string urlSPSite)
        {
            strExportXml = new StringBuilder();

            using (SPSite site = new SPSite(urlSPSite))
            {
                String fileName = groupName + "-" + termsetName + ".xml";
                fileName = fileName.Replace("/", "").Replace("\\", "").Replace(" ", "");

                // function that return termstore from site.
                termStore = termstorefromWebApp(site);

                Group   group   = termStore.Groups[groupName];
                TermSet termSet = group.TermSets[termsetName];

                String termsetNameFr = String.Empty;
                try
                {
                    PropertyInfo namesProperty = termSet.GetType().GetProperties(BindingFlags.NonPublic | BindingFlags.Instance).Single(pi => pi.Name == "Names");
                    System.Collections.Generic.Dictionary <int, string> names = (System.Collections.Generic.Dictionary <int, string>)namesProperty.GetValue(termSet, null);


                    if (names[1036] != null)
                    {
                        termsetNameFr = names[1036];
                    }
                }
                catch (System.Collections.Generic.KeyNotFoundException)
                {
                }

                strExportXml.Append("<?xml version=\"1.0\" encoding=\"utf-16\" ?>");
                strExportXml.Append("<Groups>");
                strExportXml.Append("<Group Name=\"" + groupName + "\">");
                strExportXml.Append("<TermSet Name=\"" + termsetName + "\" " + "NameFr=\"" + termsetNameFr + "\">");
                strExportXml.Append("<Terms>");

                foreach (Term trm in termSet.Terms)
                {
                    GetTerm(trm);
                }
                strExportXml.Append("</Terms>");
                strExportXml.Append("</TermSet>");
                strExportXml.Append("</Group>");
                strExportXml.Append("</Groups>");
                System.Console.WriteLine("Export Terms");
                FinalExport(directoryPath, fileName);
            }
        }