Thursday, July 26, 2012

Change the sitemap content programmatically in CRM 2011 (MSCRM)

We can change the content of the sitemap by using the CRM 2011 Webservice.
To accomplish this follow these steps

Step 1: Retrieve the sitemap



QueryExpression query = new QueryExpression();
query.EntityName = "sitemap";
query.ColumnSet = new Microsoft.Xrm.Sdk.Query.ColumnSet(true);

EntityCollection col = _service.RetrieveMultiple(query);

Entity sitemap = null;
if (col != null && col.Entities.Count > 0)
   sitemap  = col.Entities[0];

Step 2: Parse the sitemap entity to an XDocument object




string sitemapcontent = sitemap["sitemapxml"].ToString();
XDocument sitemapxml = XDocument.Parse(sitemapcontent);


You can now change the sitemap by modifying the sitemapxml object. After you made your changes, it's time to save these changes.

Step 3: Update the sitemap


sitemap["sitemapxml"] = sitemapxml.ToString();
_service.Update(sitemap);

Step 4: Publish the sitemap

Now you need to publish the sitemap.


PublishXmlRequest request = new PublishXmlRequest();
request.ParameterXml = "<importexportxml><sitemaps><sitemap></sitemap></sitemaps></importexportxml>";
_service.Execute(request);

Helpful links
http://msdn.microsoft.com/en-us/library/gg309259.aspx

1 comment:

  1. Interesting post. thanks for sharing helpful information with us. Appconsultio is an app development company in Mumbai that empowers endless Development to make a comprehensive, practical future. From concept to launch, we pride ourselves on delivering cutting-edge solutions that empower businesses to thrive in the digital landscape.

    ReplyDelete