Monday, July 18, 2011

Import Solution Into Microsoft Dynamics CRM 2011 Using .NET With ImportSolutionRequest

This illustration shows how to import a solution into Microsoft Dynamics CRM 2011 in code using C#  with the Import Solution Request.   This example will be given in C# (.NET).

JSCRIPT NOTE: At this time I am NOT providing a Jscript example on this call because of a limit in the SOAP formatter that only allows approximately 32,000 characters to a message.  Do to encoding the file in the request, the request SOAP message was over 800,000 characters. It would also be difficult to reach into a user's system to get the bytes needed anyways in a practical manner.  I am not sure there is much need to do this operation in JScript they need they can comment below and I will look into it further for them.

Ok, here is what the code look like!
First in C#:

byte[] fileBytes = File.ReadAllBytes(@"C:\code\TestSolution.zip");

ImportSolutionRequest impSolReq = new ImportSolutionRequest()
{
    CustomizationFile = fileBytes
};

ImportSolutionResponse resp = (ImportSolutionResponse)service.Execute(impSolReq);

If you need help instantiating a service object in .NET within a plugin check out this post:
http://mileyja.blogspot.com/2011/04/instantiating-service-object-within.html

I hope this helps!

2 comments:

  1. Hi
    I wanted to create a custom IMport Process which imports the solution, and then imports additional data in CRM. In my situation I cannot create a custom Asp.Net Website and I must do all with Javascript. What do you think the best options are? Is there a way to achieve this?

    Thanks

    ReplyDelete
    Replies
    1. Hello Besir, the reason that I didn't supply a jscript component was partially the message size issue related to my SOAP formatter solution. The other issue was that you would have to provide some sort of a trusted interface for the jscript to obtain the bytes for your solution file. I am not sure how you would go about reaching into your file system in Jscript to provide the file bytes in jscript. There are security limits there that don't exist in ASP.NET due to the ability to use dialogs.

      Delete