Advertisement
Guest User

createtemplate

a guest
Apr 26th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.ServiceModel.Description;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Microsoft.Xrm.Sdk;
  9. using Microsoft.Xrm.Sdk.Client;
  10. using Microsoft.Xrm.Sdk.Messages;
  11.  
  12. namespace BPCreateEditTemplateTesting
  13. {
  14.     class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             #region Login
  19.             var clientCredentials = new ClientCredentials();
  20.             clientCredentials.UserName.UserName = "brukernavn";
  21.             clientCredentials.UserName.Password = "passord";
  22.  
  23.             var server = "";
  24.             var organization = "boligpartnerutvikling";
  25.  
  26.             var url = $"{(string.IsNullOrWhiteSpace(server) ? $"https://{organization}.api.crm4.dynamics.com" : $"{server}/{organization}")}/XrmServices/2011/Organization.svc";
  27.             var serviceProxy = new OrganizationServiceProxy(new Uri(url), null, clientCredentials, null);
  28.             #endregion Login
  29.  
  30.             var filepath = @"C:\test\rinoyeah.docx";
  31.  
  32.             var documentTemplate = new Entity("documenttemplate")
  33.             {
  34.                 Id = Guid.Parse("0b488a25-dc07-e711-8116-3863bb34d9e0"),
  35.                 ["name"] = "upsertTest",
  36.                 ["documenttype"] = new OptionSetValue(2),
  37.                 ["content"] = Convert.ToBase64String(File.ReadAllBytes(filepath))
  38.             };
  39.  
  40.             //var test = localContext.Service.Execute(new UpsertRequest { Target = documentTemplate });
  41.             var test = serviceProxy.Create(documentTemplate);
  42.  
  43.             Console.WriteLine("Finished!");
  44.             Console.ReadKey();
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement