[SP-2010]dev gestion de document C#
bonjour à tous!
je dois réaliser un dev lié à de la gestion de documents. et accéder aux méta-données de documents dans une bibliothéque Sharepoint.
apparement, celon les sources que l'on m'a fourni, on peut accéder aux propriétés par une gestion évènementielle de la liste (procédures ItemAdded, ItemUpdated par exemple). Il faut créer une classe qui hérite de la classe Microsoft. SharePoint. SPItemEventReceiver.
voilà pour la base! on m'a fourni un peu de code pour m'aider a comprendre... mais sa m'embrouille un peu, j'arrive a comprendre "a peu près" la procédure ItemAdded mais pour ItemUpdated... bah je comprend vraiment rien.
j'aurais besoin d'un peu d'aide pour m'éclaircir ce code:
Code:
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.IO;
namespace NVL_MOSS_Reunion
{
public class ObjectifReunion : SPItemEventReceiver
{
private const String strSite = "adresse de mon site";
private const String strLibObj = "Mes Devis";
private const String strLstReu = "Réunions";
private const String strLstTach = "Tâches Réunion";
private const String strLibDoc = "Comptes rendus Réunion";
private const String strRepTmp = "chemin de dossier";
// Evénement de liste "Réunions" : Après Ajout
public override void ItemAdded(SPItemEventProperties p)
{
SPSite site = new SPSite(strSite);
SPWeb web = site.OpenWeb();
SPDocumentLibrary libObjectifs = (SPDocumentLibrary)web.Lists[strLibObj];
SPList listeReu = web.Lists[strLstReu];
String s = p.AfterProperties["Title"].ToString();
foreach (SPListItem elementO in libObjectifs.Items)
{
if (elementO["Traité"].Equals(false))
{
foreach (SPListItem elementR in listeReu.Items)
{
if (elementR["Title"].ToString().Equals(s))
{
elementO["Réunion"] = elementR.ID;
elementO.Update();
break;
}
}
}
}
}
// Evénement de liste "Réunions" : Après Modification
public override void ItemUpdated(SPItemEventProperties p)
{
SPSite site = new SPSite(strSite);
SPWeb web = site.OpenWeb();
SPList listeReu = web.Lists[strLstReu];
SPList listeTaches = web.Lists[strLstTach];
SPDocumentLibrary libOjectifs = (SPDocumentLibrary)web.Lists[strLibObj];
String titleReunion = p.ListItem["Title"].ToString();
String lieu = p.ListItem["Lieu"].ToString();
int codeReunion = p.ListItemId;
if (p.ListItem["Validée"].Equals(true))
{
StreamWriter sw = new StreamWriter(strRepTmp + "CR " + titleReunion + ".html", false, Encoding.UTF8);
sw.WriteLine("<html><body>");
sw.WriteLine("<h2 align='center'>Compte Rendu : " + titleReunion + "</h2><hr>");
// Gestion des objectifs
sw.WriteLine("<font color='#008000'><h3 align='center'>Liste des objectifs</h3></font>");
sw.WriteLine("<table align='center' width='75%' border='1'>");
sw.WriteLine("<tr><th>Objectif</th><th>Traité ?</th><th>Décision</th></tr>");
foreach (SPListItem elementO in libOjectifs.Items)
{
int pos = elementO["Réunion"].ToString().IndexOf(";");
String code = elementO["Réunion"].ToString().Substring(0, pos);
if (codeReunion.ToString().Equals(code))
{
String choix = "";
if (elementO["Traité"].Equals(true))
choix = "Oui";
else
choix = "Non";
//Oter l'extension du nom du document
String nomObj = elementO["Nom"].ToString();
pos = elementO["Nom"].ToString().IndexOf(".");
if (pos != -1)
nomObj = elementO["Nom"].ToString().Substring(0, pos);
sw.WriteLine("<tr><td align='center'>" + nomObj + "</td><td align='center'>" + choix
+ "</td><td align='center'>" + elementO["Décision"] + "</td></tr>");
}
}
sw.WriteLine("</table>");
// Gestion des tâches
sw.WriteLine("<font color='#008080'><h3 align='center'>Liste des tâches</h3></font>");
sw.WriteLine("<table align='center' width='75%' border='1'>");
sw.WriteLine("<tr><th>Titre</th><th>Assignée à</th><th>Début</th><th>Echéance</th><th>Etat</th></tr>");
foreach (SPListItem e in listeTaches.Items)
{
String libReunion = "";
int pos = e["Réunion"].ToString().IndexOf("#");
if (pos != -1)
libReunion = e["Réunion"].ToString().Substring(pos + 1);
if (libReunion.Equals(titleReunion))
{
//Oter l'Id, le ; et le dièse de l'assigné
int posDiese = e["Assigné à"].ToString().IndexOf("#");
String affectation = "";
if (posDiese != -1)
{
affectation = e["Assigné à"].ToString().Substring(pos + 1);
}
//Oter heure Date de début
String datedebut = "";
int posEspace = e["Date de début"].ToString().IndexOf(" ");
if (posEspace != -1)
{
datedebut = e["Date de début"].ToString().Substring(0, posEspace);
}
//Oter heure Echéance
String echeance = "";
posEspace = e["DueDate"].ToString().IndexOf(" ");
if (posEspace != -1)
{
echeance = e["DueDate"].ToString().Substring(0, posEspace);
}
sw.WriteLine("<tr align='center'><td>"+e["Title"]+"</td><td>"+affectation+"</td><td>"+
datedebut+"</td><td>"+echeance+"</td><td>"+
e["Status"]+"</td></tr>");
}
}
sw.WriteLine("</table><br>");
sw.WriteLine("<p align='center'><font size='+1'><b><a href='#' onclick='javascript:window.history.back();'>Retour</a></b></font></p>");
sw.WriteLine("</body></html>");
sw.Close();
SPDocumentLibrary libReunions = (SPDocumentLibrary)web.Lists[strLibDoc];
byte[] bytes = File.ReadAllBytes(strRepTmp + "CR " + titleReunion + ".html");
SPFile f = libReunions.RootFolder.Files.Add("Compte rendu " + titleReunion + ".html", bytes, true);
libReunions.Update();
f.Properties["Réunion"] = titleReunion;
f.Update();
libReunions.Update();
File.Delete(strRepTmp + "CR " + titleReunion + ".html");
}
}
}
} |