As part of a InfoPath web-enabled form, we want to include the ability for form fillers to upload files and documents to a location outside the form (meaning no embedded attachments).
We figured a Documents Library would be the most suitable for this, but I'm not sure how we can introduce the type of functionality we need.

Basically, While filling out the form a specific name is made (which becomes the name of the form when submitted) that becomes the name of the a second-level sub-folder in the documents library, for which it is expected the documents to be uploaded to. In theory this sub-folder would have been created already (but ideally we should have some programmability to do this upon name generation), and we can use a web-part inside the form for seamless integration.

Unfortunately, I cannot figure out how to embed a web-part into the form by any means. I found ways to embed a form in a sharepoint page, but that's actually going backwards.

Is this even possible?


I've had this requirement before, and each time I stray away from InfoPath and tell my users the only reasonable way is to use customized SharePoint list forms, edit/display/new.

But in InfoPath, you would have to write code-behind in the InfoPath form, making it administrative approved. In the code, you would, upon submission of a document attachment, use C# to post that document to the document library of your choice. You can either post whenever the attachment is chosen, or whenever the form is saved.


// 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;

Reference: http://www.bizsupportonline.net/blog/2010/01/upload-document-sharepoint-infopath-form/

  • Yeah, unfortunately I can't add custom code to the form. :/ So it seems that the answer to the base question "Can I embed a web-part in a form" is "No". – Tsaukpaetra Aug 29 '14 at 16:15

I've done something similar with Nintex, allowing for the form to receive attachments, then using workflow tools, extract the base 64 encoded attachment and load it into a document library with a web service operation, then update the form xml to remove the attachment.

Perhaps though with a form rule, once the field is assigned that determines the name, you can use a web service operation to create the folder, then provide a link on the form to open that folder in a new tab to allow them to upload the documents.

  • This sounds do-able. What kind of web service operation is available? – Tsaukpaetra Aug 28 '14 at 22:54
  • Any of the SharePoint REST or SOAP web services can be called within Infopath – Eric Alexander Aug 28 '14 at 23:10
  • I'm having trouble doing this it seems. I'm trying to use the following URL as a test, but it doesn't seem to work. mysite.domain.com/my/tsaukpaetra/_api/web/… – Tsaukpaetra Aug 28 '14 at 23:12

For scenarios like this I have used an add-in to InfoPath, since I cannot write the code required for that functionality.

Qdabra Software has a tool called qRules that contains commands to do many things with InfoPath that can only be done with code, but you only use the user interface to activate these commands via rules. The tool is not free but costs less than a developer would charge for a day's work.

Uploading files to a Sharepoint library from within a browser form is one of the commands included in qRules.

Please keep in mind that this will require browser forms and will not work with list forms.

I'm not affiliated with the company. Just a happy customer.

  • Hmm, I'm not sure if I could even do this, it looks like Sandboxed-something-or-other isn't enabled by the administrator, and I can't add any custom code to the form. So it sounds like there are no "Vanilla" methods to even embed the library as a webpart? Hmm this project keeps getting more interesting... – Tsaukpaetra Aug 28 '14 at 22:52

I ended up taking the simplest route, and made a calculated hyperlink instead. It basically lead to the Document Library, with &IsDlg=2 appended.

Kinda clunky, but it works with no fuss in trying to get upper management to approve better (and more appropriate) permissions on the site. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.