Unanswered Publish Infopath form which has image object(Base64Binary)

  • Thursday, June 07, 2007 6:26 PM
     
     

    Hello Folks,

     

        Whenever i'd like to publish the template(which has Image Attachment(base64binary as datatype)), it showing following exception.

    The selected field cannot be promoted because its datatype is not supported: base64binary

     

    I'd appreciate if you folks can help me to resolve this problem - My requirement is, i need to publish attachment column into Forms Library as URL column.

     

    Please do the needful.

     

    Thanks

All Replies

  • Friday, June 08, 2007 11:18 AM
     
     

    Sorry - this can't be done directly. InfoPath cannot promote a field to a URL column and attachments are embedded within the InfoPath XML document.

     

    You would have to submit the InfoPath form to a custom web service that extracts the attachment from the form XML, saves the attachment to a document library, saves the form to a document library, then sets the URL column value for the new SPListItem to the URL of the attachment.

     

  • Tuesday, June 12, 2007 1:44 PM
     
     

    David,

    I'm having this problem as well.  Are there any default web services available to do this or do you know of a site that has samples of this type of web service that can be modified to fit what a person needs?  I keep seeing references to creating a web service, but can't find a walk thru to building one.

     

    Thanks in advance for any help you can provide.

  • Wednesday, June 13, 2007 2:46 AM
     
     

    If you set the form to be browser enabled you should not have the option of adding a image attachment.  However, you can have a regular attachment, which is base 64, plus it is has some InfoPath headers.  A web service can accept this.  Here is a class that you can use for it based on some other info, there is another code option that you can find here: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1507940&SiteID=1 .  The web service can actually accept the base 64 field as a byte array.  An easy way to create the object that the WS receives is to save the files as source files and then run the xsd gen tool to create your class.  I don't know if this is what you are looking for, but I hope it helps:

    Code Snippet

    using System;

    using System.Collections.Generic;

    using System.Text;

     

    using System.IO;

     

    namespace CTED.InfoPath

    {

        /// <summary>

        /// Class used to decode an InfoPath attachment.

        /// Pulls the file name and the decoded file from either a base 64 byte array or string.

        /// </summary>

        public class InfoPathAttachmentDecoder

        {

            //  Private string to hold the attachment name.

            string _fileName;

     

            //  Private byte array to hold the decoded attachment.

            byte[] _decodedFile;

     

            /// <summary>

            /// The name of the file within the InfoPath attachment.

            /// </summary>

            public string Filename

            {

                get { return _fileName; }

            }

     

            /// <summary>

            /// The decoded file within the InfoPath attachment.

            /// </summary>

            public byte[] DecodedFile

            {

                get { return _decodedFile; }

            }

     

            /// <summary>

            /// Constructor for the InfoPathAttachmentDecoder Class

            /// </summary>

            /// <param name="base64EncodedString">The attachment represented by a string</param>

            public InfoPathAttachmentDecoder(string base64EncodedString)

            {

                //  Use unicode encoding.

                Encoding _encoding = Encoding.Unicode;

     

                //  The byte array containing the data.

                byte[] _data = Convert.FromBase64String(base64EncodedString);

     

                //  Use a memory stream to access the data.

                using (MemoryStream _memoryStream = new MemoryStream(_data))

                {

                    //  Create a binary reader from the stream.

                    BinaryReader _theReader = new BinaryReader(_memoryStream);

     

                    //  Create a byte array to hold the header data.

                    byte[] _headerData = _theReader.ReadBytes(16);

     

                    //  Find the file size before finding the file name.

                    int _fileSize = (int)_theReader.ReadUInt32();

     

                    //  Get the file name.

                    int _attachmentNameLength = (int)_theReader.ReadUInt32() * 2;

                    byte[] _fileNameBytes = _theReader.ReadBytes(_attachmentNameLength);

                    _fileName = _encoding.GetString(_fileNameBytes, 0, _attachmentNameLength - 2);

     

                    //  Get the decoded attachment.           

                    _decodedFile = _theReader.ReadBytes(_fileSize);

                }

            }

           

            /// <summary>

            /// Constructor for the InfoPathAttachmentDecoder Class

            /// </summary>

            /// <param name="base64EncodedBytes">The attachment represented by a byte array</param>

            public InfoPathAttachmentDecoder(byte[] base64EncodedBytes) : this(Convert.ToBase64String(base64EncodedBytes)) { }

     

            /// <summary>

            /// Static method that gets the file from the attachment.

            /// </summary>

            /// <param name="base64EncodedString">The attachment represented by a string</param>

            /// <returns>Returns a byte array of the file in the attachment.</returns>

            public static byte[] DecodeInfoPathAttachment(string base64EncodedString)

            {

                //  Create an instance of the InfoPathAttachmentDecoder

                InfoPathAttachmentDecoder _infoPathAttachmentDecoder = new InfoPathAttachmentDecoder(base64EncodedString);

               

                //  Return the decoded file.

                return _infoPathAttachmentDecoder.DecodedFile;

            }

     

            /// <summary>

            /// Static method that gets the file from the attachment.

            /// </summary>

            /// <param name="base64EncodedBytes">The attachment represented by a byte array</param>

            /// <returns>Returns a byte array of the file in the attachment.</returns>

            public static byte[] DecodeInfoPathAttachment(byte[] base64EncodedBytes)

            {

                //  Create an instance of the InfoPathAttachmentDecoder

                InfoPathAttachmentDecoder _infoPathAttachmentDecoder = new InfoPathAttachmentDecoder(base64EncodedBytes);

               

                //  Return the decoded file.

                return _infoPathAttachmentDecoder.DecodedFile;

            }

     

  • Monday, September 28, 2009 10:59 AM
     
     
    is there any news?