Creating your custom solution for MS CRM 4.0 - Programmatically fetch Isv Config and Sitemap for an organization

The CRM SDK provides ExportXmlRequest in order to export any customizations programatically. For example, the isv config for an organization can be exported as :
 CrmServiceRef.ExportXmlRequest exportRequest = new CrmServiceRef.ExportXmlRequest();

// Define the nodes to retrieve, the site map and the isv configuration.

exportRequest.ParameterXml = @"<importexportxml>
<entities></entities>
<nodes>
<node>isvconfig</node>
</nodes>
<securityroles></securityroles>
<settings></settings>
<workflows></workflows>
</importexportxml>";

// Execute the request.
CrmServiceRef.ExportXmlResponse isvconfigXml = (CrmServiceRef.ExportXmlResponse)crmService.Execute(exportRequest);
Alternatively, in order to read the contents of the ISV Config or Sitemap for any organization using code, the "organizationid" attribute for the organization class can be used as well. This is explained as follows:

In order to read the isv.config content :
1. Use the Discovery service to get the organization id for the organization.
2. Query the "isvconfig" entity (use QueryByAtrribute based on the attribute "organizationid") and fetch the "configxml" attribute. This returns the xml content for the isv.config file of a particular organization.

To access the sitemap xml content:
1. Use the Discovery service to get the organization id for the organization.
2. Fetch the organization instance using CrmService.Retrieve based on organization id.
3. Read the "sitemapxml" attribute of the organization retrieved.
The code sample here illustrates this:
CrmServiceRef.ColumnSet cols = new CrmServiceRef.ColumnSet();
cols.Attributes = new string[] { strpSITEMAPXML };

CrmServiceRef.organization org = (CrmServiceRef.organization)crmService.Retrieve(CrmServiceRef.EntityName.organization.ToString(),organizationid, cols);
CrmServiceRef.ColumnSet cols = new CrmServiceRef.ColumnSet();
if (org != null)
{
String strSitemapBackupPath = @"C:\Sitemap Backup\orgSitemap.xml";
// Create an instance of StreamWriter to write text to a file.
// The using statement also closes the StreamWriter.
using (StreamWriter sw = new StreamWriter(strSitemapBackupPath))
{
// Write the customization XML to the file
sw.Write(org.sitemapxml);
}
}

Comments

Popular posts from this blog

The key specified to compute a hash value is expired, only active keys are valid.

IFD Implementation for custom web pages and Anonymous Access

Using CRM Services to create or update records in large numbers