{"id":12797,"date":"2018-08-31T20:10:24","date_gmt":"2018-08-31T14:40:24","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=12797"},"modified":"2018-08-31T20:10:24","modified_gmt":"2018-08-31T14:40:24","slug":"update-and-publish-multiple-sitemap-xml-programmatically-in-dynamic-365","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2018\/08\/update-and-publish-multiple-sitemap-xml-programmatically-in-dynamic-365\/","title":{"rendered":"Update and Publish Multiple Sitemap XML Programmatically in Dynamics 365"},"content":{"rendered":"<h2><strong>Introduction:<\/strong><\/h2>\n<p>As we all know we can edit Sitemap by using Microsoft Dynamic Site Map Designer or SiteMap Editor using XrmToolBox. But, we can\u2019t see the updated changes on the Site Map until we save and publish that sitemap.<\/p>\n<p>Whereas we can also update SiteMap programmatically, after update we need to publish the sitemap XML programmatically<\/p>\n<p>In our recent <a href=\"https:\/\/www.inogic.com\/blog\/2018\/07\/how-to-retrieve-sitemap-xml-programmatically-in-dynamic-365\/\" target=\"_blank\" rel=\"noopener noreferrer\">blog<\/a> we discussed about how to retrieve SiteMap XML programatically.<\/p>\n<p>And in this blog, we will discuss about how to update and Publish Sitemap XML programmatically.<\/p>\n<p><strong>Step 1:- Update Sitemap Programmatically <\/strong><\/p>\n<p>Suppose we have multiple SiteMap XML collection,<\/p>\n<pre class=\"lang:default decode:true \">EntityCollection sitemaps = _service.RetrieveMultiple(query1);\n\tforeach (Entity entSiteMap in sitemaps.Entities)\n       {\n\n\t\tEntity updateSiteMap = null;\n\t\tXElement subAreaElement;\n\t\t\n\t\t\/\/\t\nXDocument document = XDocument.Parse(entSiteMap[\"sitemapxml\"].ToString());\n\t\t\n\t\t\/\/Specify Area from default site map\n       \tXElement area = document.Descendants(\"Area\").Where(ele =&gt; appArea.Contains((string)ele.Attribute(\"Id\"))).FirstOrDefault();\n\n\t\t\/\/To get specific area in site map by area id\nXElement area1 = document.Descendants(\"Area\").Where(ele =&gt; (string)ele.Attribute(\"Id\") == \u201cArea ID\u201d).FirstOrDefault();\n\n       \t\/\/Specify the Group of default sitemap.\n              XElement group = document.Descendants(\"Group\").Where(ele =&gt; appGroup.Contains((string)ele.Attribute(\"Id\"))).FirstOrDefault();\n\n\t\t\/\/Specify the Group of sitemap by group Id.\n\t\tXElement group1 = document.Descendants(\"Group\").Where(ele =&gt; (string)ele.Attribute(\"Id\") == \u201cGroup ID\u201d).FirstOrDefault();\n\n\t\t\/\/Add new SubArea \n\t\tsubAreaElement.Add(new XElement(\"Titles\",\n                    new XElement(\"Title\",\n                    new XAttribute(\"LCID\", ENGLISH),\n                    new XAttribute(\"Title\", \u201cDisplay Name\u201d))\n                    ));\n\t\t\n\t\t\/\/Add subarea into group.\n              group.Add(subAreaElement);\n\n\t\t\/\/Updating Sitemap\n              updateSiteMap = new Entity(\u201csitemap\u201d);\n                updateSiteMap.Id = entSiteMap.Id;\n               \n                updateSiteMap[\"sitemapxml\"] = document.ToString(SaveOptions.DisableFormatting);\n\t\t\/\/Update site map\n                service.Update(updateSiteMap);\n\n            }\n<\/pre>\n<p><strong>Step 2:- Publish Sitemap Programmatically<\/strong><\/p>\n<pre class=\"lang:default decode:true\">string siteMap = string.Empty;\nstring parameterXML = string.Empty;\n\n\/\/Object of PublishXmlRequest\nPublishXmlRequest publishXmlRequest = null;\n\n\/\/SiteMap is not null \nif (sitemaps != null)\n       {\n    foreach (Entity appSiteMapEntity in sitemaps.Entities)\n           {\n\t\/\/Add multiple sitemap into appSiteMap string \n              siteMap = siteMap + \"&lt;sitemap&gt;\" + appSiteMapEntity.Id + \"&lt;\/sitemap&gt;\";\n           }\n       }\n \t\n\/\/Add appsitemap string into &lt;importexportxml&gt;\nparameterXML = \"&lt;importexportxml&gt;&lt;sitemaps&gt;\" + appSiteMap + \"&lt;\/sitemaps&gt;&lt;\/importexportxml&gt;\";\n\n\/\/Add parameterXML string PublishXmlRequest\npublishXmlRequest = new PublishXmlRequest\n       {\n       \tParameterXml = parameterXML\n       \n};\n\n\t\/\/Execute publishXmlRequest to Publish sitemap\nService.Execute(publishXmlRequest);<\/pre>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p>We can publish updated sitemap xml using PublishXmlRequest in Dynamics 365 using the code given above.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-pack\/click-2-export-microsoft-dynamics-crm-reports\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter  wp-image-10864\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2017\/12\/Click2Export-banner.png\" alt=\"Export Dynamics CRM Reports\" width=\"828\" height=\"207\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: As we all know we can edit Sitemap by using Microsoft Dynamic Site Map Designer or SiteMap Editor using XrmToolBox. But, we can\u2019t see the updated changes on the Site Map until we save and publish that sitemap. Whereas we can also update SiteMap programmatically, after update we need to publish the sitemap XML\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2018\/08\/update-and-publish-multiple-sitemap-xml-programmatically-in-dynamic-365\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":12817,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,18,19],"tags":[1628,1629],"class_list":["post-12797","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","tag-sitemap-xml-dynamics-365","tag-sitemap-xml-dynamics-crm"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=12797"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12797\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/12817"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=12797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=12797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=12797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}