-1

How do I do that?

I need to import (and map) a CSV file to a custom entity in CRM 2011.

I am running an on-premise instance of CRM 2011 and need to use the late bound entities approach.

I have already tried following this example: Export and import a data map but failed miserably (ImportMap not found - what assembly is it in?).

  • Can you show your CSV file data ? Does your custom entity have all fields for data in your CSV ?? – Dot_NET Pro Nov 14 '17 at 05:39
  • @Dot_NETPro It has 3 columns and MANY rows, like 100 000+. I need to use those as strings, so this is not an issue. Also, no header row. – Marek Sagan Nov 18 '17 at 07:48

2 Answers2

0

ImportMap is an entity in CRM rather than a class in the SDK Assemblies. To get that example code to compile you'll need to have a class that represents the ImportMap entity, which is the early-bound model of CRM programming.

You can find the class ImportMap in the file MyOrganizationCrmSdkTypes.cs in the SDK. Adding that file to your project will give you early bound classes for all the out-of-box entities. Alternatively, you could use CrmSvcUtil (included with the SDK), or a 3rd party tool (such as Daryl Labar's or XrmToolkit) to generate just the ImportMap early-bound class.

Aron
  • 3,877
  • 3
  • 14
  • 21
0

Hi you can do something like below programatically, without creating early-bound classes.

using (StreamReader reader = new StreamReader("D://yourfileFolder//file.txt"))
    {
       string line;
       while ((line = reader.ReadLine()) != null && line!=String.Empty)
       {
       var values = line.Split(','); //your data separator, it could be any character

       Entity customEntity = new Entity("entityLogicalName");

       //you should adjust the values according to the data-type on Dynamics CRM e.g
       // customEntity ["revenue"] = new Money(values[0].ToString());


       customEntity ["field1"] = values[0]; 
       customEntity ["field2"] = values[1];
       customEntity ["field3"] = values[2];
       orgService.Create(customEntity);
       }
  }
Dot_NET Pro
  • 2,095
  • 2
  • 21
  • 38