Sometimes you want to enable anonymous access to be able to add a list item but at the same time attaching some documents.
After good few hours playing around trying to make this work, turns out that we can achieve this functionality. The trick is to use RunWithElevatedPrivileges method for the file upload. We also want the file upload functionality to be available on the NewForm.aspx as it wouldn't make sense to put it in other forms as any user would be able to upload files to other records.
The result will be something like this:
When it is saved, the user is redirected to the display form:
The close button then will take the user back to the homepage (or any page you desire)
1. Create an ascx control to host your file upload control in your project.
The code behind:
2. Create custom form template. You have to put the ascx in the CONTROLTEMPLATES folder of the 15 hive. Then find ListForm rendering template from the DefaultTemplates.ascx and copy to the custom template ascx. Register the control from step 1 and modify the following table: