Fixing the "Selected file was not found” Error When Adding an Attachment to an InfoPath Workflow Task Form
Posted by DevExpert on July 1st, 2009
If you’re at all familiar with creating Visual Studio-authored workflows for SharePoint, you’re probably aware that you can also create custom task forms for tasks that have been assigned in that workflow. The task forms can either be implemented as ASP.NET forms or InfoPath forms. My personal preference is InfoPath, provided the functionality that is needed can be accomplished using InfoPath. By choosing InfoPath, much of the overhead required to allow SharePoint to use it as a task form is already done, whereas with ASP.NET it’s up to the developer to implement.
On a recent project, I had a need to create a workflow that at a certain step, prompted the user to upload a file attachment. InfoPath was the obvious choice because they’re simple to create, simple to deploy, and they even support attachments. After creating the form and the workflow I tried attaching a file to the InfoPath task form, and received the following error message:
Another approach documented here suggests modifying the application.master master page file to add the necessary enctype form tag:
While both of these approaches work, I wasn’t completely happy with modifying out-of-the-box SharePoint files, which isn’t recommended anyways. I took a slightly more involved, but much more reusable approach. Any customization you make to SharePoint really should be implemented as a Feature. I’m not going to go into the nuts and bolts of what features are, but you can learn a little more about them from this previous post. Before I explain my approach, here are your options for accomplishing this:
- Modify the out-of-the-box application.master master page file on the file system. Not recommended.
- Modify the out-of-the-box WrkTaskIP.aspx page on the file system. Not recommended.
- Create a user control with the necessary script and deploy it as a delegate control feature. Recommend, and the approach I describe in this post.
The first step is creating the user control that will be responsible for adding the encoding to the form. I took a little different approach here too, and used jQuery to attach the encoding element to the forms. Obviously this implies that the jQuery library is being referenced already. There are other solutions that make this a cinch to accomplish, such as this one by the great Jan Tielens. In fact, this solution uses the exact same approach that I’m blogging about here. My DevExpertise.TaskFormEncoding.ascx user control looks like this:
Now that I have the user control created, I need to create a SharePoint feature to insert this into a delegate control placeholder. Both the default.master page and application.master pages that SharePoint use by default have a delegate control named AdditionalPageHead, which is there specifically for this purpose – to add script, CSS references, etc. to the page’s HEAD section:
The following snippet is my feature.xml file, which defines the feature. This file is responsible for specifying the feature ID, Title, Description, etc., plus any element manifests that our feature requires:
This feature is expecting an elements.xml manifest file, which is responsible for wiring up my custom user control to the AdditionalPageHead delegate control in the master page:
The only thing left is packaging everything up and deploying it. I always package my features up into solution packages using WSPBuilder, since a solution package can be used to deploy other feature-dependant files to SharePoint’s 12 folder structure. My entire solution folder structure looks like this:
Create the solution package, deploy it to SharePoint, and you will have a site collection feature ready for activation:
That’s it! Now you can successfully add attachments:
I’m feeling generous today and decided to include the solution package for your downloading pleasure. As always, it comes as-is and without warranty: