It is very common that you would need to import customizations from a file and upload it directly on CRM then publish thes customizations OR the opposite: where you import customisations from Dynamic CRM implementation and export to a file either XML file or a Zip file which you can then archive or add to your source control (TFS or Source Safe). The later is specially common when you need to have a regular backup of your customizations that is stored in TFS or your choses Source control.
To do this, MSDN provides several ways of importing and exporting files (see: http://msdn.microsoft.com/en-us/library/cc151164.aspx)
This is what you can do:
Export All XML customizations is usually the most popular one. Here is how you can do it (Code from MSDN):
// Set up the CRM Service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the request.
ExportAllXmlRequest request = new ExportAllXmlRequest();
// Execute the request.
ExportAllXmlResponse response = (ExportAllXmlResponse)service.Execute(request);
// Load the results into an XML document.
XmlDocument entityXml = new XmlDocument();
entityXml.LoadXml(response.ExportXml);
As for Import All XML customization followed by a publish, here is the code for it:
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// This is a potentially long running operation. The default 90-second
// time-out might be too short. Set the time-out to be 5 minutes.
// This property takes milliseconds.
service.Timeout = 300 * 1000;
// Create the request.
ExportAllXmlRequest request = new ExportAllXmlRequest();
// Execute the request.
ExportAllXmlResponse exportResponse = (ExportAllXmlResponse)service.Execute((Request)request);
// Create the request.
ImportAllXmlRequest importRequest = new ImportAllXmlRequest();
// Tell the request where the temporary XML file is located.
importRequest.CustomizationXml = exportResponse.ExportXml;
// Execute the import.
ImportAllXmlResponse importResponse = (ImportAllXmlResponse)service.Execute(importRequest);
Finally to publish your customizations, this is what you need to do:
// Set up the CRM service.
CrmAuthenticationToken token = new CrmAuthenticationToken();
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
token.OrganizationName = "AdventureWorksCycle";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
// Create the request.
PublishAllXmlRequest request = new PublishAllXmlRequest();
// Execute the request.
PublishAllXmlResponse response = (PublishAllXmlResponse)service.Execute(request);
Like this:
Like Loading...