File Attachment Control in Repeating Section - InfoPath Dev
in

InfoPath Dev

File Attachment Control in Repeating Section

Last post 08-14-2012 04:51 AM by Jimmy. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-23-2012 07:55 AM

    File Attachment Control in Repeating Section

    I have an InfoPath 2007 form with a File Attachment control within a repeating section and a save button outside of the repeating section. When an attachment is added, the save button can be use to save the attachment to a SharePoint document library. However, when the repeating section is used, the save button only saves the first attachment and none of the attachments that have been created with the repeating section. 

    Is there any way to save the other attachments that have been created with the repeating section? Below is my code.

     public void ScoutTestSubmit_Clicked(object sender, ClickedEventArgs e)
            {
            
         // Retrieve the value of the attachment in the InfoPath form
                XPathNavigator ipFormNav = MainDataSource.CreateNavigator();
                XPathNavigator nodeNav = ipFormNav.SelectSingleNode("/my:myFields/my:Scout_Test_Report/my:Scout_Test_Attach_Document_Group/my:Scout_Test_Attach_Document_Section/my:Scout_Test_Attach_Document", NamespaceManager);

                string attachmentValue = string.Empty;

         // Get the value of Well Connect Fields
                string formNumberUpdate = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:MeterConnectDateTimeValue", NamespaceManager).Value;
                string formSectionUpdates = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:MeterConnectCurrentFormSectionWF", NamespaceManager).Value;
       
                if (nodeNav != null && !String.IsNullOrEmpty(nodeNav.Value))
                {
                    attachmentValue = nodeNav.Value;

         // Decode the InfoPath file attachment
                    InfoPathAttachmentDecoder dec = new InfoPathAttachmentDecoder(attachmentValue);
                    string fileName = dec.Filename;
                    byte[] data = dec.DecodedAttachment;
       
        // Add the file to a document library
                    using (SPSite site = new SPSite(serverName + "/" + siteCollName))
                    {
                        using (SPWeb web = site.OpenWeb())
                        {
                            web.AllowUnsafeUpdates = true;

                            SPFolder lib = web.GetFolder("Meter Connect Attachements");
                            SPFile file = lib.Files.Add(fileName, data, true);
                            file.Item["Meter Connect Form Number"] = "Req_" + formNumberUpdate;
                            file.Item["Form Section Attachment"] = formSectionUpdates;
                            file.Item.Update();
                            file.Update();

                            //SPFolder docLib = web.Folder["Meter Connect Attachements"];
                            //docLib.Files.Add(fileName, data);
                            ////update metadata
                            //docLib.Item["Meter Connect Form Number"] = metadataUpdate;
                            //docLib.Item["Form Section Attachment"] = formSectionUpdate;
                            //docLib.Item.Update();
                            web.AllowUnsafeUpdates = false;
                            web.Close();
                        }
                        site.Close();
                    }
                }
            }
        }
    }
     






           
       
     

     

  • 08-13-2012 10:28 PM In reply to

    Re: File Attachment Control in Repeating Section

     Hey, Deejay.  Did you ever find a solution to this?  It describes exactly what I am trying to do and the problems I've encountered.

     

    Thanks,

    Bruce

  • 08-14-2012 04:51 AM In reply to

    Re: File Attachment Control in Repeating Section

    Instead of selecting just one instance of the attachment with SelectSingleNode(), you need to select all of them using Select() and then iterate through them.  Alternatively, you could use the SaveToSharePoint command in qRules, that makes saving out attachments easy as pie.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.