Search code examples
dynamics-crmdynamics-crm-2011crmmicrosoft-dynamicsdynamics-crm-online

MS CRM 2011 CSV import (programatically)


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?).


Solution

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