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 (932 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