Get Attachment Name - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Get Attachment Name

Last post 03-31-2023 10:50 AM by Rockie. 23 replies.
Page 2 of 2 (24 items) < Previous 1 2
Sort Posts: Previous Next
  • 05-05-2010 12:28 AM In reply to

    change the paragraph private void DecodeAttachment(BinaryReader theReader) { byte[] headerData = new byte[FIXED_HEADER]; headerData = theReader.ReadBytes(headerData.Length); fileSize = (int)theReader.ReadUInt32(); attachmentNameLength = (int)theReader.ReadUInt32() * 2; byte[] fileNameBytes = theReader.ReadBytes(attachmentNameLength); // byte[] fileNameBytes = theReader.ReadBytes(attachmentNameLength); Encoding enc = Encoding.Unicode; attachmentName = enc.GetString(fileNameBytes, 0, attachmentNameLength -2 ); decodeAttachment = theReader.ReadBytes(fileSize); } actually you only need to change the line attachmentName = enc.GetString(fileNameBytes, 0, attachmentNameLength -2 );

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 06-17-2010 05:02 PM In reply to

    Hi Qazi, I have found that the solution above works great for IP 2007, however I have been unsuccessful in running it in IP 2010.  The problem seems to be in the calculation of the filename which is unfortunately needed in my case.  Have you seen this, is there any solution that you know of?


  • 06-18-2010 04:22 PM In reply to

    We have GetAttachmentAttribute command in qRules v2.2, which is going to release soon. That command gets a specific attribute(like attribute name, extenstion, size, file) of a file attachment or a picture attachment. That command works on IP 2007, as well as IP 2010.

    stay tuned!

    Aruna Akella
    Qdabra® Software /
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
  • 02-25-2015 10:17 AM In reply to

     Hi - this is a while since your post but I have a situation where I have to be able to harvest the full path name of the attachment - not just the filename, which I have been able to do. Do you have any information about other attributes, how I might get the full pathname, etc? Thx, John Marno

  • 02-25-2015 10:24 AM In reply to

     Hi Qazi,

    Thanks for the great post - it works well for the filename - but I also need the full pathname - driveletter:\directory\subdirectory1\...\subdirectoryX\filename.ext

     Is that possible? Is it in the encoded file somewhere?

     I am wondering if the Attachment Control has any attributes itself?

     Oh - and I experienced a big shock when my test InfoPath solution worked with your code but then when I added it to my real version that has an External Item Picker (to grab data from BCS), I get an error and have discovered that Browser Based Forms cannot have both EIPs and User Code....Do you have any thoughts or comments on that?

     THanks in advance.


    John Marno


  • 07-11-2018 05:30 PM In reply to

     How does the work with InfoPath 2013


  • 07-12-2018 08:08 AM In reply to

    The initial response in this thread from Qazi Anis should work in IP 2013 C# code.
    Hilary Stoupa

  • 07-17-2018 09:03 AM In reply to

    • jd422
    • Not Ranked
    • Joined on 07-22-2010
    • Pennsylvania, USA
    • Posts 6

     I see that there are nice replies for C code (C#, at least).  I hope it's OK for me to give my solution for vbScript in case someone Googles it.

    Function AttachmentFileName(ByRef node)
     Dim nodeValue, i, filenameSize
     Dim HexString

     HexString = ""

     If(node.text <> "") Then
      'typecast the node to base64 as Infopath doesn't do this in node definition
      node.DataType = "bin.base64" 'Doing this will prevent the user from deleting the attachment
              'Change the data type back to "" when done.
      'convert base64 node value to binary and store in nodeValue byte array
      nodeValue = node.nodeTypedValue
      AttachmentFileName = "Nothing attached.  First attach a file."
      Exit Function
     End If

     'Convert ByteArray to HexString
     For i = 1 to LenB(nodeValue)
      HexString = HexString & Right("0" & Hex(AscB(MidB(nodeValue, i, 1))), 2)
      If(i = 300) Then 'Assuming header is no longer than 300 bytes
       exit for
      end if

     AttachmentFileName = ""
     filenameSize = 0

     'The length of the filenamebuffer is stored on pos 20-24 (byte), which means 41.47 in Hex and 1 as startpos for Arrays
     filenameSize = getFilenameSize(HexString,41,47)

     'Read the filename from position (49 to filenamebuffer * unicode - "\n") as end char
     AttachmentFileName = getFileName(HexString,49,filenameSize*4 + 49 - 2)
     node.DataType = "" 'This will allow the user to remove the attachment if desired
     'MsgBox filename 'Uncomment for debugging
    End Function

     Function getFilenameSize(data, startLoop, stopLoop)
     dim k
     dim size

     for k = startLoop to stopLoop step 2
      dim y1
      dim y2
      dim y3
      y1 = Mid(data,k,2)
      y2 = CLng("&h" & y1)
      y3 = y3 + Int(y2)
      size = y3
     getFilenameSize = size
    End Function

    Function getFileName(data, startLoop, stopLoop)
     dim k
     dim filename

     for k = startLoop to stopLoop step 4
      dim h1
      dim h2
      dim h3
      h1 = Mid(data,k,2)
      h2 = CLng("&h" & h1)
      h3 = Chr(h2)
      if(h3 <> "") then
       filename = filename & Cstr(h3)
      end if
     getFileName = filename
    End Function

  • 03-31-2023 10:50 AM In reply to

    • Rockie
    • Not Ranked
    • Joined on 12-09-2022
    • Posts 3
    Qazi Anis, I know many Years have passed, but thank You much! :)
Page 2 of 2 (24 items) < Previous 1 2
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.