Results 1 to 4 of 4

Thread: InfoPath base64 File Type

  1. #1

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    InfoPath base64 File Type

    I have an InfoPath XML file with a File Attach control. The file gets saved to the XML in base64. I can use Convert.FromBase64String to convert the data back into the original file, but the problem is, I have to know what kind of file it was. I am doing this: The problem is, what if the file attached wasn't a word doc, what if it was a Excel file? Is there a way to know what kind of file it is so I can save it with the correct extension? Can I possibly get the entire original file name?
    VB Code:
    1. Dim binaryData() As Byte = Convert.FromBase64String(b64str)
    2. Dim fs As New FileStream("myFile.doc",   FileMode.CreateNew)
    3. fs.Write(binaryData, 0, binaryData.Length)
    4. fs.Close()
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: InfoPath base64 File Type

    I recently ran into this myself, and I don't think there's any way to determine the original file name. Although I think that Word docs (maybe excel also) have the file name embedded somewhere. Of course you'd have to know what kind of file it is to be able to parse and grab that file name.

    In my case I got lucky because they're all image files, and I save them all with .jpg extension. My app displays the images in a browser, and neither IE or FF cares if it's really, say, a .gif.

    I think you'd have to read the header of the file to find out what type of file it is. Could be a daunting task if you have lots of possible file types. When I was doing this, I was thinking it'd be nice if the xml had an element that specified the file name, but that may not be the case.

  3. #3

    Thread Starter
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141

    Re: InfoPath base64 File Type

    Here is what MSDN says: I guess the base64 conversion has to be done, then read the header and remove it from the file. My problem is, I don't understand this header stuff.
    Upon attaching a file, InfoPath first builds a header structure which includes information about the file being attached. The structure consists of the following:


    · BYTE[4]: Signature (based on the signature for PNG):

    (decimal) 199 73 70 65
    (hexadecimal) C7 49 46 41
    (ASCII C notation) \307 I F A


    The first byte is chosen as a non-ASCII value to reduce the probability that a text file may be misrecognized as a file attachment. The rest identifies the file as an InfoPath File Attachment.


    · DWORD: Size of the header

    · DWORD: IP Version

    · DWORD: dwReserved

    · DWORD: File size

    · DWORD: Size of file name buffer

    · File name buffer: variable size


    After building the header structure described above, the header and file data are concatenated and base64 encoded. This base64 data is then stored with the XML data in the form.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: InfoPath base64 File Type

    Looks like they give you the file name, which is good. I've never dealt with InfoPath, but it looks like you'd have to read the length of the file name, then extract the file name itself. Since it's concatenated and encoded, what's that look like when you decode?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width