Is there a way to Retrieve, Export (or Package) a Solution in code ?
I´m working with dynamics 2016
*This post is locked for comments
Is there a way to Retrieve, Export (or Package) a Solution in code ?
I´m working with dynamics 2016
*This post is locked for comments
Hi jhon
Could you please to explain more about your code?
how to run the code?
is it a DLL or not?
Thanks
BR
Thanks to all. I´ve done this code and works.
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System;
using System.Activities;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Text;
namespace DynamicsSolutions.CRMGenericTools.Utilities.General
{
class ExportASolution : CodeActivity
{
[RequiredArgument]
[Input("Solution Unique Name")]
public InArgument<string> SolutionUniqueName { get; set; }
[RequiredArgument]
[Input("Place where is the folder on the local PC")]
public InArgument<string> FolderPlace { get; set; }
private ITracingService m_tracingService;
private void Trace(string message)
{
if (this.m_tracingService != null)
{
this.m_tracingService.Trace(message);
}
}
protected override void Execute(CodeActivityContext executionContext)
{
IWorkflowContext extension1 = executionContext.GetExtension<IWorkflowContext>();
IOrganizationService organizationService = executionContext.GetExtension<IOrganizationServiceFactory>().CreateOrganizationService(new
Guid?(((IExecutionContext)extension1).UserId));
try
{
this.Run(organizationService,
this.SolutionUniqueName.Get(executionContext),
this.FolderPlace.Get(executionContext));
}
catch (FaultException<OrganizationServiceFault> ex)
{
ex.ToString();
}
}
public void Run(IOrganizationService service,
string solutionUniqueName,
string folderPlace)
{
try
{
//Export is taking from CRM and saving on the local PC
solutionUniqueName.e
ExportSolutionRequest exportSolutionRequest = new ExportSolutionRequest();
exportSolutionRequest.Managed = false;
exportSolutionRequest.SolutionName = solutionUniqueName;
ExportSolutionResponse exportSolutionResponse = (ExportSolutionResponse)service.Execute(exportSolutionRequest);
byte[] exportXml = exportSolutionResponse.ExportSolutionFile;
string filename = solutionUniqueName + ".zip";
//string test = "@"" + filename + """;
if (Directory.Exists(folderPlace))
{
File.WriteAllBytes(folderPlace + filename, exportXml);
}
else
{
throw new Exception("The folder doesn´t exists");
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
ex.ToString();
}
}
}
}
XrmToolbox has a Solution Packager Plugin available: www.xrmtoolbox.com/plugins
Hello John,
Here is the simple article to retrieve solution using c#. You can create console and try.
jkkdynamiccrm.blogspot.in/.../export-solution-using-c-code-from-ms-crm.html
Hope this helps.
Hi Jhon,
You can find the sample code in the following location in the download package: www.microsoft.com/.../details.aspx
SampleCode\CS\Solutions\WorkWithSolutions.cs
You can modify it to meet your needs and then compile it.
Hope this helps
Radu
Have used this code for previous project:
public EntityCollection RetrieveSolutions(string solutionName)
{
QueryExpression query = new QueryExpression
{
EntityName = "solution",
ColumnSet = new ColumnSet(true),
Criteria =
{
Conditions =
{
new ConditionExpression("uniquename", ConditionOperator.Equal, solutionName)
},
}
};
RetrieveMultipleRequest request = new RetrieveMultipleRequest();
request.Query = query;
try
{
RetrieveMultipleResponse response = (RetrieveMultipleResponse)service.Execute(request);
EntityCollection results = response.EntityCollection;
return results;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new Exception(ex);
}
}
public bool ImportSolution(string fileName)
{
byte[] fileBytes = File.ReadAllBytes(fileName);
ImportSolutionRequest request = new ImportSolutionRequest()
{
CustomizationFile = fileBytes
};
try
{
ImportSolutionResponse response = (ImportSolutionResponse)service.Execute(request);
return true;
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new Exception(ex);
}
}
Use ExportSolutionRequest to Export a solution.
Hope this helps.
Thanks.
Is there a tool, a web page or a github code that makes it ?
Hi Jhon,
You can use the ExportSolutionRequest (msdn.microsoft.com/.../microsoft.crm.sdk.messages.exportsolutionrequest.aspx)
You can check following sample code provided by MS: msdn.microsoft.com/.../gg509050.aspx
Regards,
Radu
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
52
Victor Onyebuchi
6