How to Create Connection to SharePoint and Dynamic CRM using C#.
- Connection establish in SharePoint using C#
- Reference DLL you need for this code is -
- Microsoft.SharePoint.Client.Latest by Trujillo
- Microsoft.SharePoint.Client.Runtime by Trujillo
- Below mention is c# code -
- Connection establish in Dynamic CRM using C#
- nuget packages you need for this code is -
- Install-Package Microsoft.CrmSdk.Extensions
- Install-Package Microsoft.CrmSdk.CoreAssemblies
- Below mention is c# code -
public static string SharePointUrl = "https://CompanyName.sharepoint.com/";
public static string UserName = "UserName@CompanyName.onmicrosoft.com", PassWord = "o365_Password";
static void Main(string[] args)
{
//----------Establish a connection with Microsoft SharePoint.
SecureString passWord = new SecureString();
foreach (char c in PassWord.ToCharArray()) passWord.AppendChar(c);
using (ClientContext clientContext = new ClientContext(SharePointUrl))
{
try
{
clientContext.Credentials = new SharePointOnlineCredentials(UserName, passWord);
}
catch (Exception ex)
{
Console.WriteLine("error while establish a SharePoint connection: " + ex.Message.ToString());
}
// Open the web
var web = clientContext.Web;
}
}
public static Guid _accountId;
static void Main(string[] args)
{
string connectionString = "Url = https://CompanyName.crm.dynamics.com/; Username=UserName@CompanyName.onmicrosoft.com; Password=o365_Password;";
CrmConnection connection = CrmConnection.Parse(connectionString);
OrganizationService service = new OrganizationService(connection);
OrganizationServiceContext context = new OrganizationServiceContext(service);
Entity account = new Entity("account");
account["name"] = "Fourth Coffee";
// Create an account record named Fourth Coffee.
_accountId = service.Create(account);
}
Comments
Post a Comment