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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 146 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 59

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans