SharePoint 2013 anonymous access add attachments to list item
Hi,
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:
Put the below script in the ascx as well (credit to this post):
The code behind:
3. The last step is to add a FeatureActivated receiver in order to set the template name (I use content type for my lists). Also your code needs to break list inheritance and specify AddListItems permission for the anonymous users.
HTH,
Andreas
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)
The steps:
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:
HTH,
Andreas
I am impressed by the quality of information on this website. There are a lot of good resources here. Thanks for sharing !
ReplyDelete