Tuesday, May 31, 2022

Console application to create a .csv file and Add data and Retrieve, and update data into D365

Console application to create a .csv file and Retrieve, and update data into D365

Here in this blog, I have covered 3 scenarios, follow the step by step process to learn and write a better console app within 5 - 10 mins:

1. Write a Console Application to Retrieve or Fetch contact records from Dynamics 365.
2. Create a .csv file and write records into a CSV file row-wise.
3. Read records from the CSV file and Update Contact Records back in CRM

Follow the step by step process :

1. Open Visual Studio Application
2. Navigate to File -> Click on new Project...
3. Select Visual C# -> Console Application(.Net Framework)
4. Give a name to your console application (e.g. ConsoleApp1)
5. Set the location where you want to store your console project (e.g. C:\Users\Console Project)
6. Provide a solution name (e.g. MyConsoleAppSolution)
7. Choose the right Framework and Click Ok to save your console application project.











Once saved the folder structure will look like as shown on the screen below:









Let's begin with your coding part:

1.  First Go to References Add required assembly References from the NuGet Package:
You can see in the below screen, that these are the mandatory references that are required for your console app. Once you added you can verify it in your reference file.


2. Open > App.config file > Write below code in that.

In App.config file you add your connectionStrings and if you have any key-value pair you can add it inside appSettings. Follow the code below.