IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Voir le flux RSS

Blog d'un SharePointeur

Traitement de type "batch"

Noter ce billet
par , 20/02/2015 à 22h20 (805 Affichages)
Bonjour,

Lorsque l'on à besoin d'effectuer un grand nombre de traitement sur des listes (création, modification, suppression), il est très fortement déconseillé de le faire via une itération du type foreach.
L'API SharePoint met à notre disposition une méthode :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
        // Summary*:
        //     Processes the specified batch string of commands for sending multiple requests
        //     to the server per transaction.
        //
        // Parameters*:
        //   strBatchData:
        //     A Collaborative Application Markup Language (CAML) string that contains the
        //     batch string of commands, which consists of a Batch element and any number
        //     of subordinate Method elements that each specify a Windows SharePoint Services
        //     remote procedure call (RPC) method.
        //
        // Return*:
        //     A string that contains the results.
        public string ProcessBatchData(string strBatchData);
Donc pour résumé cette méthode attend en paramètre une commande batch écrite en CAML.

Voici les trois actions possibles :
  1. Création
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <Method ID="1">
            <SetList>[LIST GUID]</SetList>
            <SetVar Name="Cmd">Save</SetVar>
            <SetVar Name="ID">New</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#[Field Name]">[Value]</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#[Field Name]">[Value]</SetVar>
          </Method>
  2. Modification
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <Method ID="2">
            <SetList>71a9fac3-2e94-4246-8fec-41e30ea65b06</SetList>
            <SetVar Name="Cmd">Save</SetVar>
            <SetVar Name="ID">3</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#[Field Name]">[Value]</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#[Field Name]">[Value]</SetVar>
          </Method>
  3. Suppression
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    <Method ID="3">
            <SetList>71a9fac3-2e94-4246-8fec-41e30ea65b06</SetList>
            <SetVar Name="Cmd">Delete</SetVar>
            <SetVar Name="ID">4</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#[Field Name]">[Value]</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#[Field Name]">[Value]</SetVar>
          </Method>
    Le tout doit être structurée sous la forme :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    <?xml version="1.0" encoding="UTF-8"?>
        <ows:Batch OnError="Continue">
          <Method ID="1">
            <SetList>71a9fac3-2e94-4246-8fec-41e30ea65b06</SetList>
            <SetVar Name="Cmd">Save</SetVar>
            <SetVar Name="ID">New</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#OrderDate">2009-2-21</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#OrderDateTime">2009-2-21</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#CustomerID">1;#Cust_1</SetVar>
          </Method>
          <Method ID="2">
            <SetList>71a9fac3-2e94-4246-8fec-41e30ea65b06</SetList>
            <SetVar Name="Cmd">Save</SetVar>
            <SetVar Name="ID">3</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#OrderDate">2009-2-21</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#OrderDateTime">2009-2-21</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#CustomerID">1;#Cust_1</SetVar>
          </Method>
          <Method ID="3">
            <SetList>71a9fac3-2e94-4246-8fec-41e30ea65b06</SetList>
            <SetVar Name="Cmd">Delete</SetVar>
            <SetVar Name="ID">4</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#OrderDate">2009-2-21</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#OrderDateTime">2009-2-21</SetVar>
            <SetVar Name="urn:schemas-microsoft-com:office:office#CustomerID">2;#Cust_2</SetVar>
          </Method>
        </ows:Batch>


N'hésitez pas à demander si vous souhaitez des exemples d'utilisation en C#.

Envoyer le billet « Traitement de type "batch" » dans le blog Viadeo Envoyer le billet « Traitement de type "batch" » dans le blog Twitter Envoyer le billet « Traitement de type "batch" » dans le blog Google Envoyer le billet « Traitement de type "batch" » dans le blog Facebook Envoyer le billet « Traitement de type "batch" » dans le blog Digg Envoyer le billet « Traitement de type "batch" » dans le blog Delicious Envoyer le billet « Traitement de type "batch" » dans le blog MySpace Envoyer le billet « Traitement de type "batch" » dans le blog Yahoo

Catégories
C# , DotNET , C#

Commentaires