Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 15.04 KB | None | 0 0
  1. namespace WAZVerwaltung.Console
  2. {
  3.     using Microsoft.SharePoint.Client;
  4.     using SharePointManipulator.Library.Services;
  5.     using System.Security;
  6.  
  7.     public class Startup
  8.     {
  9.         public static void Main()
  10.         {
  11.             string siteUrl = "https://onevirtualoffice.sharepoint.com/sites/ct_dev_ln/APP0008";
  12.             string userName = @"jordan.georgiev@external.atlascopco.com";
  13.             SecureString password = "Atlas2017".ConvertToSecureString();
  14.  
  15.             using (ClientContext context = new ClientContext(siteUrl))
  16.             {
  17.                 context.Credentials = new SharePointOnlineCredentials(userName, password);
  18.                 RegisterRibbonCustomActionsToChargensuchenListView(context);
  19.                 //RegisterRibbonCustomActionsToChargensuchenListDocumentSet(context);
  20.                 RegisterRibbonCustomActionsToIdentnummernListView(context);
  21.                 //RegisterRibbonCustomActionsToIdentnummernListDocumentSet(context);
  22.             }
  23.         }
  24.  
  25.         private static void RegisterRibbonCustomActionsToChargensuchenListView(ClientContext clientContext)
  26.         {
  27.             string scriptSrc = "~Site/SiteAssets/Scripts/RibbonCustomActionsScript.js";
  28.             string customActionName = "WAZVerwaltung.Chargensuchen.CreateNewItem";
  29.             string scriptLinkName = "WAZVerwaltung.Chargensuchen.NewItem";
  30.             string listTitle = "Chargensuchen";
  31.             string customActionLocation = "CommandUI.Ribbon";
  32.             string commandUIExtension = string.Concat(
  33.                 "<CommandUIExtension>",
  34.                     "<CommandUIDefinitions>",
  35.                         "<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">",
  36.                                 "<Button ",
  37.                                     "Id=\"WAZVerwaltung.Chargensuchen.Ribbon.IdentnummerVergeben\" ",
  38.                                     "Alt=\"Identnummer vergeben\" ",
  39.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  40.                                     "Command=\"WAZVerwaltung_Chargensuchen_CreateNewItemIdentnummerVergeben\" ",
  41.                                     "LabelText=\"Identnummer vergeben\" ",
  42.                                     "TemplateAlias=\"o1\"/>",
  43.                             "</CommandUIDefinition>",
  44.                             "<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">",
  45.                                 "<Button ",
  46.                                     "Id=\"WAZVerwaltung.Chargensuchen.Ribbon.Umstempelung\" ",
  47.                                     "Alt=\"Umstempelung\" ",
  48.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  49.                                     "Command=\"WAZVerwaltung_Chargensuchen_CreateNewItemUmstempelung\" ",
  50.                                     "LabelText=\"Umstempelung\" ",
  51.                                     "TemplateAlias=\"o1\"/>",
  52.                             "</CommandUIDefinition>",
  53.                         "</CommandUIDefinitions>",
  54.                         "<CommandUIHandlers>",
  55.                             "<CommandUIHandler ",
  56.                                 "Command=\"WAZVerwaltung_Chargensuchen_CreateNewItemIdentnummerVergeben\" ",
  57.                                 "CommandAction=\"javascript: wazVerwaltung.Chargensuche.IdentnummerVergeben('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" ",
  58.                                 "EnabledScript=\"javascript: SP.ListOperation.Selection.getSelectedItems().length == 1;\" />",
  59.                                 "<CommandUIHandler ",
  60.                                 "Command=\"WAZVerwaltung_Chargensuchen_CreateNewItemUmstempelung\" ",
  61.                                 "CommandAction=\"javascript: wazVerwaltung.Umstempelung('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" ",
  62.                                 "EnabledScript=\"javascript: SP.ListOperation.Selection.getSelectedItems().length == 1;\" />",
  63.                         "</CommandUIHandlers>",
  64.                     "</CommandUIExtension>");
  65.  
  66.             SPMListsService listService = new SPMListsService(clientContext);
  67.  
  68.             // Create the Export & Import custom actions
  69.             listService.CreateCustomAction(listTitle, customActionName, customActionLocation, commandUIExtension, 15, PermissionKind.ViewListItems);
  70.  
  71.             // Attach the SpreadsheetActions.js file to scriptlink custom action
  72.             listService.CreateScriptLink(scriptSrc, scriptLinkName, 21);
  73.         }
  74.         private static void RegisterRibbonCustomActionsToChargensuchenListDocumentSet(ClientContext clientContext)
  75.         {
  76.             string scriptSrc = "~Site/SiteAssets/Scripts/RibbonCustomActionsScript.js";
  77.             string customActionName = "WAZVerwaltung.Chargensuchen.CreateNewItemDocumentSet";
  78.             string scriptLinkName = "WAZVerwaltung.Chargensuchen.NewItemDocumentSet";
  79.             string listTitle = "Chargensuchen";
  80.             string customActionLocation = "CommandUI.Ribbon";
  81.  
  82.             string commandUIExtension = string.Concat(
  83.                 "<CommandUIExtension>",
  84.                     "<CommandUIDefinitions>",
  85.                         "<CommandUIDefinition Location=\"Ribbon.ManageDocumentSet.MDS.Manage.Controls._children\">",
  86.                                 "<Button ",
  87.                                     "Id=\"WAZVerwaltung.Chargensuchen.DocumentSet.Ribbon.IdentnummerVergeben\" ",
  88.                                     "Alt=\"Identnummer vergeben\" ",
  89.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  90.                                     "Command=\"WAZVerwaltung_Chargensuchen_DocumentSet_CreateNewItemIdentnummerVergeben\" ",
  91.                                     "LabelText=\"Identnummer vergeben\" ",
  92.                                     "TemplateAlias=\"o1\"/>",
  93.                             "</CommandUIDefinition>",
  94.                             "<CommandUIDefinition Location=\"Ribbon.ManageDocumentSet.MDS.Manage.Controls._children\">",
  95.                                 "<Button ",
  96.                                     "Id=\"WAZVerwaltung.Chargensuchen.DocumentSet.Ribbon.Umstempelung\" ",
  97.                                     "Alt=\"Umstempelung\" ",
  98.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  99.                                     "Command=\"WAZVerwaltung_Chargensuchen_DocumentSet_CreateNewItemUmstempelung\" ",
  100.                                     "LabelText=\"Umstempelung\" ",
  101.                                     "TemplateAlias=\"o1\"/>",
  102.                             "</CommandUIDefinition>",
  103.                         "</CommandUIDefinitions>",
  104.                         "<CommandUIHandlers>",
  105.                             "<CommandUIHandler ",
  106.                                 "Command=\"WAZVerwaltung_Chargensuchen_DocumentSet_CreateNewItemIdentnummerVergeben\" ",
  107.                                 "CommandAction=\"javascript: wazVerwaltung.Chargensuche.IdentnummerVergeben('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" />",
  108.                             "<CommandUIHandler ",
  109.                                 "Command=\"WAZVerwaltung_Chargensuchen_DocumentSet_CreateNewItemUmstempelung\" ",
  110.                                 "CommandAction=\"javascript: wazVerwaltung.Umstempelung('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" />",
  111.                         "</CommandUIHandlers>",
  112.                     "</CommandUIExtension>");
  113.  
  114.             SPMListsService listService = new SPMListsService(clientContext);
  115.  
  116.             // Create the Export & Import custom actions
  117.             listService.CreateCustomAction(listTitle, customActionName, customActionLocation, commandUIExtension, 15, PermissionKind.ViewListItems);
  118.  
  119.             // Attach the SpreadsheetActions.js file to scriptlink custom action
  120.             listService.CreateScriptLink(scriptSrc, scriptLinkName, 21);
  121.         }
  122.  
  123.         private static void RegisterRibbonCustomActionsToIdentnummernListView(ClientContext clientContext)
  124.         {
  125.             string scriptSrc = "~Site/SiteAssets/Scripts/RibbonCustomActionsScript.js";
  126.             string customActionName = "WAZVerwaltung.Identnummern.CreateNewItem";
  127.             string scriptLinkName = "WAZVerwaltung.Identnummern.NewItem";
  128.             string listTitle = "Identnummern";
  129.             string customActionLocation = "CommandUI.Ribbon";
  130.             string commandUIExtension = string.Concat(
  131.                 "<CommandUIExtension>",
  132.                     "<CommandUIDefinitions>",
  133.                         "<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">",
  134.                                 "<Button ",
  135.                                     "Id=\"WAZVerwaltung.Identnummern.Ribbon.IdentnummerVergeben\" ",
  136.                                     "Alt=\"Identnummern anlagen\" ",
  137.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  138.                                     "Command=\"WAZVerwaltung_Identnummern_CreateNewItemIdentnummernAnlagen\" ",
  139.                                     "LabelText=\"Identnummern anlagen\" ",
  140.                                     "TemplateAlias=\"o1\"/>",
  141.                             "</CommandUIDefinition>",
  142.                             "<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">",
  143.                                 "<Button ",
  144.                                     "Id=\"WAZVerwaltung.Identnummern.Ribbon.Umstempelung\" ",
  145.                                     "Alt=\"Umstempelung\" ",
  146.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  147.                                     "Command=\"WAZVerwaltung_Identnummern_CreateNewItemUmstempelung\" ",
  148.                                     "LabelText=\"Umstempelung\" ",
  149.                                     "TemplateAlias=\"o1\"/>",
  150.                             "</CommandUIDefinition>",
  151.                         "</CommandUIDefinitions>",
  152.                         "<CommandUIHandlers>",
  153.                             "<CommandUIHandler ",
  154.                                 "Command=\"WAZVerwaltung_Identnummern_CreateNewItemIdentnummernAnlagen\" ",
  155.                                 "CommandAction=\"javascript: wazVerwaltung.Identnummern.IdentnummernAnlagen('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" ",
  156.                                 "EnabledScript=\"javascript: SP.ListOperation.Selection.getSelectedItems().length == 1;\" />",
  157.                                 "<CommandUIHandler ",
  158.                                 "Command=\"WAZVerwaltung_Identnummern_CreateNewItemUmstempelung\" ",
  159.                                 "CommandAction=\"javascript: wazVerwaltung.Umstempelung('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" ",
  160.                                 "EnabledScript=\"javascript: SP.ListOperation.Selection.getSelectedItems().length == 1;\" />",
  161.                         "</CommandUIHandlers>",
  162.                     "</CommandUIExtension>");
  163.  
  164.             SPMListsService listService = new SPMListsService(clientContext);
  165.  
  166.             // Create the Export & Import custom actions
  167.             listService.CreateCustomAction(listTitle, customActionName, customActionLocation, commandUIExtension, 15, PermissionKind.ViewListItems);
  168.  
  169.             // Attach the SpreadsheetActions.js file to scriptlink custom action
  170.             listService.CreateScriptLink(scriptSrc, scriptLinkName, 21);
  171.         }
  172.         private static void RegisterRibbonCustomActionsToIdentnummernListDocumentSet(ClientContext clientContext)
  173.         {
  174.             string scriptSrc = "~Site/SiteAssets/Scripts/RibbonCustomActionsScript.js";
  175.             string customActionName = "WAZVerwaltung.Identnummern.CreateNewItemDocumentSet";
  176.             string scriptLinkName = "WAZVerwaltung.Identnummern.NewItemDocumentSet";
  177.             string listTitle = "Identnummern";
  178.             string customActionLocation = "CommandUI.Ribbon";
  179.             string commandUIExtension = string.Concat(
  180.                 "<CommandUIExtension>",
  181.                     "<CommandUIDefinitions>",
  182.                         "<CommandUIDefinition Location=\"Ribbon.ManageDocumentSet.MDS.Manage.Controls._children\">",
  183.                                 "<Button ",
  184.                                     "Id=\"WAZVerwaltung.Identnummern.DocumentSet.Ribbon.IdentnummerVergeben\" ",
  185.                                     "Alt=\"Identnummern anlagen\" ",
  186.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  187.                                     "Command=\"WAZVerwaltung_Identnummern_DocumentSet_CreateNewItemIdentnummernAnlagen\" ",
  188.                                     "LabelText=\"Identnummern anlagen\" ",
  189.                                     "TemplateAlias=\"o1\"/>",
  190.                             "</CommandUIDefinition>",
  191.                             "<CommandUIDefinition Location=\"Ribbon.ManageDocumentSet.MDS.Manage.Controls._children\">",
  192.                                 "<Button ",
  193.                                     "Id=\"WAZVerwaltung.Identnummern.DocumentSet.Ribbon.Umstempelung\" ",
  194.                                     "Alt=\"Umstempelung\" ",
  195.                                     "Sequence=\"40\" Image32by32=\"~site/SiteAssets/create-new-item.png\" ",
  196.                                     "Command=\"WAZVerwaltung_Identnummern_DocumentSet_CreateNewItemUmstempelung\" ",
  197.                                     "LabelText=\"Umstempelung\" ",
  198.                                     "TemplateAlias=\"o1\"/>",
  199.                             "</CommandUIDefinition>",
  200.                         "</CommandUIDefinitions>",
  201.                         "<CommandUIHandlers>",
  202.                             "<CommandUIHandler ",
  203.                                 "Command=\"WAZVerwaltung_Identnummern_DocumentSet_CreateNewItemIdentnummernAnlagen\" ",
  204.                                 "CommandAction=\"javascript: wazVerwaltung.Identnummern.IdentnummernAnlagen('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" />",
  205.                                 "<CommandUIHandler ",
  206.                                 "Command=\"WAZVerwaltung_Identnummern_DocumentSet_CreateNewItemUmstempelung\" ",
  207.                                 "CommandAction=\"javascript: wazVerwaltung.Umstempelung('{SelectedItemId}', '{SelectedListId}', '{SiteUrl}');\" ",
  208.                                 "EnabledScript=\"javascript: SP.ListOperation.Selection.getSelectedItems().length == 0;\" />",
  209.                         "</CommandUIHandlers>",
  210.                     "</CommandUIExtension>");
  211.  
  212.             SPMListsService listService = new SPMListsService(clientContext);
  213.  
  214.             // Create the Export & Import custom actions
  215.             listService.CreateCustomAction(listTitle, customActionName, customActionLocation, commandUIExtension, 15, PermissionKind.ViewListItems);
  216.  
  217.             // Attach the SpreadsheetActions.js file to scriptlink custom action
  218.             listService.CreateScriptLink(scriptSrc, scriptLinkName, 21);
  219.         }
  220.     }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement