bonjour;
j'ai fait ce code qui marche très bien dans une webpart mais dans une application services par-exemple ça ne marche pas avec l'erreur "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
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
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 //récupérer le nom et le nombre de bytes string NomFile = new System.IO.FileInfo(item).Name; long byteLength = new System.IO.FileInfo(item).Length; /// using (ClientContext clientContext = new ClientContext("http://mssharepoint:22222")) { var list = clientContext.Web.Lists.GetByTitle("Fichier"); clientContext.Load(list); ListItemCreationInformation itemInformation = null; SP.ListItem listItem = list.AddItem(itemInformation); //ajout du nom dans la liste listItem["Title"] = NomFile; listItem.Update(); ///////*****************/////// clientContext.ExecuteQuery(); CamlQuery query = new CamlQuery(); query.ViewXml = @"<View><Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>" + NomFile + "</Value></Eq></Where></Query></View>"; var refreshedItem = list.GetItems(query); clientContext.Load(refreshedItem); clientContext.ExecuteQuery(); ///////*****************/////// FileStream fs = new FileStream(item, FileMode.Open, FileAccess.Read); /// if (!string.IsNullOrEmpty(item) && byteLength > 0) { WSLists.Lists listsWS = new WSLists.Lists(); listsWS.UseDefaultCredentials = true; byte[] buffer = new byte[byteLength]; fs.Read(buffer, 0, (int)byteLength); fs.Close(); //ajout de l'attachement listsWS.AddAttachment("Fichier", refreshedItem[0].Id.ToString(), item, buffer); } } <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> <table cellspacing='5' width='100%' > <tr> <td colspan='2'> <WebPartPages:WebPartZone runat="server" FrameType="None" ID="Main" Title="loc:Main"> <ZoneTemplate> <WebPartPages:ContentEditorWebPart runat="server" __MarkupType="xmlmarkup" WebPart="true" __WebPartId="{549F89CB-E839-4CC9-B51A-4A401E95D9CB}" > <WebPart xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/WebPart/v2"> <Title>Composant WebPart Éditeur de contenu</Title> <FrameType>Default</FrameType> <Description>À utiliser pour des images, des tableaux et du texte mis en forme.</Description> <IsIncluded>true</IsIncluded> <PartOrder>1</PartOrder> <FrameState>Normal</FrameState> <Height /> <Width /> <AllowRemove>true</AllowRemove> <AllowZoneChange>true</AllowZoneChange> <AllowMinimize>true</AllowMinimize> <AllowConnect>true</AllowConnect> <AllowEdit>true</AllowEdit> <AllowHide>true</AllowHide> <IsVisible>true</IsVisible> <DetailLink /> <HelpLink /> <HelpMode>Modeless</HelpMode> <Dir>Default</Dir> <PartImageSmall /> <MissingAssembly>Impossible d'importer ce composant WebPart.</MissingAssembly> <PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge> <IsIncludedFilter /> <ExportControlledProperties>true</ExportControlledProperties> <ConnectionID>00000000-0000-0000-0000-000000000000</ConnectionID> <ID>g_549f89cb_e839_4cc9_b51a_4a401e95d9cb</ID> <ContentLink xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" /> <PartStorage xmlns="http://schemas.microsoft.com/WebPart/v2/ContentEditor" /> </WebPart> </WebPartPages:ContentEditorWebPart> </ZoneTemplate> </WebPartPages:WebPartZone> </td> </tr> <tr> <td> <WebPartPages:WebPartZone runat="server" FrameType="None" ID="MainLeft" Title="loc:MainLeft"> <ZoneTemplate> </ZoneTemplate> </WebPartPages:WebPartZone> </td> <td> <WebPartPages:WebPartZone runat="server" FrameType="None" ID="MainRight" Title="loc:MainRight"> <ZoneTemplate></ZoneTemplate> </WebPartPages:WebPartZone> </td> </tr> </table> </asp:Content>
Partager