Bonjour à tous,

Je chercher à remplacer une image dans un fichier docx en openXML.

J'ai trouvé un morceau de code qui fait cela par contre il est en C# et je n'arrive pas à le traduit en Vb.net, voici la partie qui me pose problème.

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
 
 
 SdtBlock cc = doc.MainDocumentPart.Document.Body.Descendants<SdtBlock>()
                    .FirstOrDefault(c =>
                    {
                        SdtProperties p = c.Elements<SdtProperties>().FirstOrDefault();
                        if (p != null)
                        {
                            // Is it a picture content control?
                            SdtContentPicture pict =
                                p.Elements<SdtContentPicture>().FirstOrDefault();
                            // Get the alias.
                            SdtAlias a = p.Elements<SdtAlias>().FirstOrDefault();
                            if (pict != null && a.Val == "MyPicture")
                                return true;
                        }
                        return false;
                    });
Voici ce que j'ai traduit mais j'ai toujours des erreurs.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
 
Dim cc As SdtBlock = doc.MainDocumentPart.Document.Body.Descendants(Of SdtBlock)().FirstOrDefault(Function(c))
        Dim p As SdtProperties = c.Elements(Of SdtProperties)().FirstOrDefault()
        If (p IsNot Nothing) Then
            ' Is it a picture content control?
            Dim pict As SdtContentPicture = p.Element(Of SdtContentPicture)().FirstOrDefault()
            ' Get the alias.
            Dim a As SdtAlias = p.Elements(Of SdtAlias)().FirstOrDefault()
            If (pict IsNot Nothing And a.Val = "MyPicture") Then
                Return True
            End If
        End If
     Return False
Merci pour votre aide.