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();
}
}
}
}