I have an InfoPath 2010 form with a "Resume" attachment. When the form gets submitted to the SharePoint document library, I need to display the resume attachment as a document library's column. Every solution method that I am finding is based on InfoPath/SharePoint 2007, which is not working the same way with 2010. I know there should be a workflow to create in the SharePoint Designer, and can't figure out what it is. If anybody has this knowledge, please help.
You will have to include custom code in the submit button of your InfoPath form and you will have to give the InfoPath form template Full Trust for the code to work in SharePoint.
// Retrieve the value of the attachment in the InfoPath form
XPathNavigator ipFormNav = MainDataSource.CreateNavigator();
XPathNavigator nodeNav = ipFormNav.SelectSingleNode("//my:document", NamespaceManager);
string attachmentValue = string.Empty;
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("http://ServerName"))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPFolder docLib = web.Folders["MyDocuments"];
docLib.Files.Add(fileName, data);
web.AllowUnsafeUpdates = false;
web.Close();
}
site.Close();
}
}
Please visit the Step 5 of this post to get the different options- http://www.bizsupportonline.net/blog/2010/04/top-10-questions-infopath-file-attachments/
or view this post directly- http://www.bizsupportonline.net/blog/2010/01/upload-document-sharepoint-infopath-form/
I would recommend to move all c# code out of the InfoPath form. Full Trust forms w/ code inside couldn't be deployed w/ CI or powershell to defferent SharePoint farms and that's pity.
In that case, it's better to move code to event receiver to sync attachments between InfoPath forms and 3rd part source like additional column/list/whatever it is.