Traitement de type "batch"
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 :
Donc pour r�sum� cette m�thode attend en param�tre une commande batch �crite en CAML.
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);
Voici les trois actions possibles :
- 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>- 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>- Suppression
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 <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>
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#.