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();
}
}
}
}
}