with published adminstator approved form i can not upload file attachement in infopath in Document library with using browser - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

with published adminstator approved form i can not upload file attachement in infopath in Document library with using browser

Last post 07-19-2022 12:33 AM by Masoud. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-16-2022 01:09 PM

    with published adminstator approved form i can not upload file attachement in infopath in Document library with using browser

     Hi

    as attached form with using code like below when i am using info path form i can submit form to form library  and upload file attachment to document library. now i try to publish info path form as administrator approved form and upload in form services in SharePoint and then content type...

    now when i use browser and click submit button just form submitted to form library and it can not upload attachment in document library and i got error like below:

     

    There has been an error while processing the form.

    Click OK to resume filling out the form. You may want to check your form data for errors

     

    An entry has been added to the Windows event log of the server.
    Log ID:5337

    Correlation ID:b4ab51a0-7e47-1020-777b-27de3da6e959
     
    please guide me how i can solve this problem.

     

     

     ---------------------------------------------------------------------------------------------------

     using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Utilities;
    using System.Web;

    namespace frmdoc2
    {
        public partial class FormCode
        {
            // Member variables are not supported in browser-enabled forms.
            // Instead, write and read these values from the FormState
            // dictionary using code such as the following:
            //
            // private object _memberVariable
            // {
            //     get
            //     {
            //         return FormState["_memberVariable"];
            //     }
            //     set
            //     {
            //         FormState["_memberVariable"] = value;
            //     }
            // }

            // NOTE: The following procedure is required by Microsoft InfoPath.
            // It can be modified using Microsoft InfoPath.
            public void InternalStartup()
            {
                ((ButtonEvent)EventManager.ControlEvents["SubmitButton"]).Clicked += new ClickedEventHandler(SubmitButton_Clicked);

            }

            public void SubmitButton_Clicked(object sender, ClickedEventArgs e)
            {
                XPathNavigator docXN = this.CreateNavigator();
                XPathNavigator opnXN = docXN.SelectSingleNode("/my:myFields/my:fileAttach",
                this.NamespaceManager);
                byte[] attachmentNodeBytes = Convert.FromBase64String(opnXN.ToString());
                // Position 20 contains a DWORD indicating the length of the
                // filename buffer. The filename is stored as Unicode so the
                // length is multiplied by 2.
                int fnLength = attachmentNodeBytes[20] * 2;
                byte[] fnBytes = new byte[fnLength];
                // The actual filename starts at position 24...
                for (int i = 0; i < fnBytes.Length; i++)
                {
                    fnBytes[i] = attachmentNodeBytes[24 + i];
                }
                // Convert the filename bytes to a string. The string
                // terminates with \0 so the actual filename is the
                // original filename minus the last character !
                char[] charFileName = System.Text.UnicodeEncoding.Unicode.GetChars(fnBytes);
                string fileName = new string(charFileName);
                fileName = fileName.Substring(0, fileName.Length - 1);
                // The file is located after the header, which is 24 bytes long
                // plus the length of the filename.
                byte[] fileContents = new byte[attachmentNodeBytes.Length - (24 + fnLength)];
                for (int i = 0; i < fileContents.Length; ++i)
                {
                    fileContents[i] = attachmentNodeBytes[24 + fnLength + i];
                }
                string SiteURL = "http://www.3isco.local/Detail_eng/" + fileName;
                SPWeb site = new SPSite(SiteURL).OpenWeb();
                site.Files.Add(SiteURL, fileContents);
            }
        }
    }

  • 07-19-2022 12:33 AM In reply to

    Re: with published adminstator approved form i can not upload file attachement in infopath in Document library with using browser

    The problem was security validation of form, I found the answer in below link: https://sharepoint.stackexchange.com/questions/51927/error-adding-file-to-infopath-form-that-is-browser-enabled-in-sharepoint
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.