web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Plugin for uploading appointment file from sharepoint

(0) ShareShare
ReportReport
Posted on by 10

Hello all, i am new in plugin code. 

I have to write a plugin code for - uploading a appointment excel file to d365 prod environment . And mapping all the column of Appointment entity .

This all by doing code in c#

Can you give a brief example of similar 

I have the same question (0)
  • Vivek Profile Picture
    10 on at

    using System;

    using System.Collections.Generic;

    using System.IO;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Tooling.Connector;

    using CsvHelper;

    using System.Globalization;

    using CsvHelper.Configuration;       //download nudget package

    namespace ConsoleApp4

    {

       internal class Program

       {

           static void Main(string[] args)

           {

               string connectionName = "DEV_Connection";

               IOrganizationService svcProxy = CRMConnection(connectionName);

               if (svcProxy != null)

               {

                   string filePath = @"C:\Appointment\Appointment6.csv"; // Replace with the path to your CSV file

                   string entityName = "appointment"; // Replace with the name of your Dynamics 365 CRM entity

                   List<Entity> recordsToCreate = FetchCsvData(filePath, entityName);

                   if (recordsToCreate.Count > 0)

                   {

                       foreach (Entity record in recordsToCreate)

                       {

                           try

                           {

                               Guid createdRecordId = svcProxy.Create(record);

                               Console.WriteLine("Record created with ID: " + createdRecordId);

                           }

                           catch (Exception ex)

                           {

                               Console.WriteLine("Error creating record: " + ex.Message);

                           }

                       }

                   }

                   else

                   {

                       Console.WriteLine("No records to create.");

                   }

               }

               Console.Read();

           }

           static IOrganizationService CRMConnection(string connectionName)

           {

               CrmServiceClient devConnection = new CrmServiceClient("AuthType=Office365;Url=**********;Username=**********;Password=*********");

               IOrganizationService svcProxy = devConnection.OrganizationWebProxyClient != null ?

                   (IOrganizationService)devConnection.OrganizationWebProxyClient :

                   devConnection.OrganizationServiceProxy;

               return svcProxy;

           }

           static List<Entity> FetchCsvData(string filePath, string entityName)

           {

               List<Entity> recordsToCreate = new List<Entity>();

               using (var reader = new StreamReader(filePath))

               using (var csv = new CsvReader(reader, CultureInfo.InvariantCulture))

               {

                   var csvConfiguration = new CsvConfiguration(CultureInfo.InvariantCulture)

                   {

                       Delimiter = ",", // Set the field delimiter to a comma (,)

                       Quote = '"' // Set the data delimiter to a quotation mark (")

                   };

                   csv.Read();

                   csv.ReadHeader();

                   Dictionary<string, string> fieldMappings = new Dictionary<string, string>

                   {

                       { "Start Time", "scheduledstart" },    // mapping the field

                       { "End Time", "scheduledend" },

                       //{ "INDSKR_ACTIVITYSUBTYPE", "indskr_activitysubtype" },

                       { "INDSKR_ACTIVITYTYPE", "indskr_activitytype" },

                       { "INDSKR_EXTERNALID", "indskr_externalid" },

                       { "INDSKR_EXTERNALSOURCE", "indskr_externalsource" },

                       { "INDSKR_NOTES", "indskr_notes" },

                       { "LOCATION", "location" },

                       //{ "OWNERID", "ownerid" },

                       { "STATECODE", "statecode" },

                       //{ "STATUSCODE", "statuscode" },                  

                       { "SUBJECT", "subject" },                  

                       //{ "INDSKR_TYPE" , "indskr_type" },

                      // { "INDSKR_SUBTYPE", "indskr_subtype" },

                   };

                   while (csv.Read())

                   {

                       Entity record = new Entity(entityName);

                       foreach (var field in fieldMappings)

                       {

                           string columnName = field.Key;

                           string fieldName = field.Value;

                           string value = csv.GetField(columnName);

                           if (!string.IsNullOrEmpty(value) && value != DBNull.Value.ToString())

                           {

                               if (columnName == "Start Time" || columnName == "End Time")

                               {

                                   DateTime dateTime;

                                   if (DateTime.TryParseExact(value, "dd-MM-yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))

                                   {

                                       record[fieldName] = dateTime;

                                   }

                                   else

                                   {

                                       Console.WriteLine("Invalid date and time format: " + value);

                                       continue;

                                   }

                               }

                               else

                               {

                                   record[fieldName] = value;

                               }

                           }

                       }

                       recordsToCreate.Add(record);

                   }

               }

               return recordsToCreate;

           }

       }

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 156

#2
ManoVerse Profile Picture

ManoVerse 153 Super User 2026 Season 1

#3
Zhilan Profile Picture

Zhilan 49

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans