IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

InfoPath .NET Discussion :

Pb upload de fichier xls dans un formulaire infopath


Sujet :

InfoPath .NET

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Septembre 2013
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2013
    Messages : 3
    Points : 2
    Points
    2
    Par défaut Pb upload de fichier xls dans un formulaire infopath
    Bonjour à tous,

    J'espère que vous pourrez m'aider, voici ma situation :

    J'ai une bibliothèque sharepoint dans laquelle des utilisateurs déposent leur formulaire infopath avec en pièce jointe un fichier xls.

    J'ai un traitement quotidien qui récupère dans une base access les infos contenues dans les pièces jointes, les traitent et les réexporte en fichier excel.

    Maintenant je cherche a uploader ces fichiers excels traités dans les formulaires infopath.

    Petite précision :

    - je fais tout en VBA.
    - j'ai essayer en éditant avec notepad les formulaires infopath et en leur joignant un autre fichier xls à la place de l'ancien > ca fonctionne.
    - Dans les formulaires infopath, les fichiers sont encodés en base64

    Mon problème est lors de l'encodage mon fichier xls en base64 qui se passe bien mais lorsque j'ouvre le formulaire infopath il n'y a pas de fichier joint.

    Voici mon code

    Dim oDoc As DOMDocument
    Set oDoc = New DOMDocument
    oDoc.async = False

    Dim oStream
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Type = 1
    oStream.Open
    oStream.LoadFromFile ("C:\Temp\CLS - Maj PA9 - TL_04092013.xlsx")

    Dim oNode
    Set oNode = oDoc.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'")
    Set oNode = oDoc.insertBefore(oNode, oDoc.childNodes.Item(0))

    Dim oRoot
    Set oRoot = oDoc.createElement("Root")
    Set oDoc.documentElement = oRoot
    oRoot.setAttribute "xmlns:dt", "urn:schemas-microsoft-com:datatypes"

    Set oNode = oDoc.createElement("xlsDoc")
    oRoot.appendChild oNode
    oNode.DataType = "bin.base64"
    oNode.nodeTypedValue = oStream.Read()

    oStream.Close
    oDoc.Save ("C:\Temp\XmlOuput.xml")

    Merci de votre aide, si vous avec un code qui marche pour convertir un fichier xls en code64 et un moyen de l'intégrer à un infopath existant je suis aussi preneur. Merci

  2. #2
    Membre éprouvé
    Homme Profil pro
    Référent technique
    Inscrit en
    Juillet 2007
    Messages
    834
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 40
    Localisation : France, Pyrénées Atlantiques (Aquitaine)

    Informations professionnelles :
    Activité : Référent technique

    Informations forums :
    Inscription : Juillet 2007
    Messages : 834
    Points : 1 219
    Points
    1 219
    Par défaut
    Ah, problème épineux que l'insertion d'une pièce jointe dans un formulaire InfoPath...
    Le contrôle pièce jointe ne stocke pas uniquement le contenu du fichier mais aussi le nom de celui-ci.
    Voir ce très bon article qui explique la manipulation en sens inverse:
    http://benvanmol.blogspot.fr/2007/10...hments-in.html

    Ou encore les classes fournies par MS:
    http://support.microsoft.com/kb/892730

    Si avec cela, vous n'arrivez pas à le faire fonctionner, je rallumerai éventuellement une machine virtuelle sur laquelle j'avais implémenté cette fonctionnalité (en C#).

    Cordialement,
    Rémi MATAYRON
    N'hésitez pas à visiter mon blog dédié à InfoPath et SharePoint : http://rmatayron.blogspot.com/

    Pour plus de visibilité sur le forum, marquer la question en [Résolu] lorsque la réponse fournie vous convient.

  3. #3
    Candidat au Club
    Profil pro
    Inscrit en
    Septembre 2013
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2013
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    Merci beaucoup d'avoir répondu billout rm et surtout pour le super article mais j'ai perdu espoir de faire cette manip en VBA et je ne sais pas m'en sortir en C.

    Voici le code pour télécharger la pièce jointe de l'infopath en VBA si ca peut aider quelqu'un.

    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
    Public Function extractAttachment(strFileName, strXPath, strOutputFolder, RequestId)
        Dim iFile As Long                'binary file number index
        Dim oNode As IXMLDOMNode            'base64 data node from form field
        Dim nodeValue() As Byte             'full byte array of base64 data
        Dim fileContent() As Byte           'byte array of file data only
        Dim arrFileNameSize(4) As Byte      'byte array of file size only
        Dim arrFileName() As Byte           'byte array of filename only
        Dim arrFileData() As Byte
        Dim oDoc As DOMDocument             'XML document object to load form into
        Dim i As Long
        Dim fileNameSize As Long, headerLength As Long, fileDataLength As Long
        Dim strOutputFileName As String
     
        On Error GoTo ErrHandler
     
        'create XML document in memory
        Set oDoc = New DOMDocument
        'load form into XML document in memory
        If oDoc.Load(strFileName) = True Then
            If Not (oDoc Is Nothing) Then
                'read attachment node value to oNode object
                Set oNode = oDoc.documentElement.selectSingleNode(strXPath)
                'typecast the node to base64 as Infopath doesn't do this in node definition
                oNode.DataType = "bin.base64"
                'convert base64 node value to binary and store in nodeValue byte array
                nodeValue = oNode.nodeTypedValue
     
                'read filesize from byte position 20 (4 bytes) to byte array
                For i = 20 To 24
                    arrFileNameSize(i - 20) = nodeValue(i)
                Next
     
                'convert filesize byte array to actual file length (and multiply by 2 to get length in bytes)
                fileNameSize = ByteArraytoLong(arrFileNameSize) * 2
     
                'now we know how many bytes the filename is read in filename bytes in filename byte array
                '(filename starts at 24 and goes for filesize*2 bytes)
                ReDim arrFileName(fileNameSize - 1)
                For i = 24 To 23 + fileNameSize
                    arrFileName(i - 24) = nodeValue(i)
                Next
     
                'convert filename byte array to filename string (vba takes care of typecasting here)
                strFileName = Trim(arrFileName)
     
                'calculate filecontent byte length (equals full byte size of field - header data (default and filename))
                headerLength = 24 + fileNameSize
                fileDataLength = UBound(nodeValue) - headerLength
     
                'now make room in fileData byte array equal to this size
                ReDim arrFileData(fileDataLength)
                'store the byte data for the file in the fileData byte array
                For i = headerLength To UBound(nodeValue)
                    arrFileData(i - headerLength) = nodeValue(i)
                Next
     
                'open up output binary file
                iFile = FreeFile()
                strOutputFileName = strOutputFolder & RequestId & ".xls"
                Open strOutputFileName For Binary Access Write As iFile
     
                'output entire fileContent byte array to file
                Put iFile, , arrFileData
                Close iFile
            End If
        End If
        extractAttachment = True
     
    finish:
        Set oDoc = Nothing
        Set oNode = Nothing
        Exit Function
     
    ErrHandler:
        LogWriter LogFile, String(3, "!") & " [" & Err.Source & "] ERROR : ExtractAttachement - id : " & RequestId
        extractAttachment = False
        GoTo finish
     
    End Function

Discussions similaires

  1. [MySQL] upload : problème fichiers existants dans la bdd ?
    Par vincedjs dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 15/02/2006, 11h29
  2. Copie de fichiers XLS dans une table
    Par sebvita dans le forum Oracle
    Réponses: 3
    Dernier message: 28/12/2005, 09h13
  3. lister fichiers xls dans combobox ?
    Par zouille dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 22/12/2005, 14h26
  4. intégrer un fichier XML dans un formulaire access
    Par lilibrik dans le forum XML/XSL et SOAP
    Réponses: 2
    Dernier message: 17/06/2005, 11h49
  5. Afficher le contenu d'un fichier xls dans un DBgrid
    Par bianconeri dans le forum C++Builder
    Réponses: 5
    Dernier message: 03/09/2004, 16h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo