Picture Control File Name Extract - InfoPath Dev
in

InfoPath Dev

Picture Control File Name Extract

Last post 04-27-2010 07:32 AM by nsdolic. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 04-27-2010 07:32 AM

    Picture Control File Name Extract

    Hi I am having following problem. In my form I have a picture control. After picture is inserted I need to know where this picture came from. (Here only file name would be sufficient).  

    Sofar, I have built a form with attachment control and using base64 encoder/ decoder I was able to extract file name. When I change attachment control to picture control I am getting Out of Memory Exeption.

     

    How can I extract name of a picure inserted into picture control?  Bellow is Decoder code I am using Thank you very much.  using System;using System.IO;using System.Text; namespace InfoPathAttachmentEncoding{    /// <summary>    /// Decodes a file attachment and saves it to a specified path.    /// </summary>    public class InfoPathAttachmentDecoder    {        private const int SP1Header_Size = 20;        private const int FIXED_HEADER = 16;         private int fileSize;        private int attachmentNameLength;        private string attachmentName;        private byte[] decodedAttachment;         /// <summary>        /// Accepts the Base64 encoded string        /// that is the attachment.        /// </summary>        public InfoPathAttachmentDecoder(string theBase64EncodedString)        {            byte[] theData = Convert.FromBase64String(theBase64EncodedString);            using (MemoryStream ms = new MemoryStream(theData))            {                BinaryReader theReader = new BinaryReader(ms);                DecodeAttachment(theReader);            }        }         private void DecodeAttachment(BinaryReader theReader)        {            //Position the reader to get the file size.            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);                       //InfoPath uses UTF8 encoding.            Encoding enc = Encoding.Unicode;            attachmentName = enc.GetString(fileNameBytes, 0, attachmentNameLength - 2);            decodedAttachment = theReader.ReadBytes(fileSize);        }           public string Filename        {            get { return attachmentName; }        }         public byte[] DecodedAttachment        {            get { return decodedAttachment; }        }    }} 

     

Page 1 of 1 (1 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.