%3CLINGO-SUB%20id%3D%22lingo-sub-509832%22%20slang%3D%22en-US%22%3EHOW%20TO%3A%20Allow%20anonymous%20users%20to%20add%20items%20to%20SharePoint%20list%20using%20client%20object%20model%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-509832%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20Jun%2013%2C%202013%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20post%20is%20a%20contribution%20from%20Charls%20Tom%20Jacob%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20blog%20is%20based%20on%20a%20support%20ticket%20I%20handled%20recently.%20The%20requirement%20was%20to%20let%20anonymous%20users%20add%20items%20to%20a%20SharePoint%20list%2Flibrary%20using%20client%20side%20object%20model(JavaScript).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20are%20the%20steps%20needed%20to%20implement%20this.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20Enable%20Anonymous%20access%20at%20the%20Web%20Application%20level%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGo%20to%20SharePoint%20Central%20Administration%20%3D%26gt%3B%20Application%20Management%2C%20select%20the%20Web%20Application%20%3D%26gt%3B%20Authentication%20Providers%2C%20click%20on%20the%20zone%2C%20and%20select%20Enable%20anonymous%20access%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20244px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111495i0FBA092BAB321FAB%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.%20Now%2C%20navigate%20to%20the%20corresponding%20web%20site%2C%20Site%20Action%20%3D%26gt%3B%20Site%20Permissions%20%3D%26gt%3B%20Anonymous%20Access.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EConfigure%20what%20anonymous%20users%20can%20access%20at%20the%20site%20level%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20244px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111496iE2EB453E4EAC2690%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E3.%20Break%20the%20permission%20inheritance%20on%20the%20specific%20list%20in%20which%20you%20want%20to%20allow%20anonymous%20users%20to%20add%20items.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENavigate%20to%20the%20list%2Flibrary%20settings%20for%20the%20list%20in%20which%20you%20want%20to%20allow%20Anonymous%20users%20to%20add%20items%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EList%20Settings%20%3D%26gt%3B%20Permissions%20for%20this%20list%20%3D%26gt%3B%20Stop%20Inheriting%20Permissions%2C%20click%20OK%20%3D%26gt%3B%20Anonymous%20Access%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESelect%20Add%20Items.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20244px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111497i1C099F460C6CDA24%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E4.%20Enable%20%E2%80%9CAddItem%E2%80%9D%20operation%20for%20the%20client%20object%20model%20for%20the%20Web%20Application.%20You%20can%20run%20the%20following%20code%20as%20a%20console%20application%20(equivalent%20powershell%20script%20also%20should%20work).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CTABLE%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%3E%3CBR%20%2F%3E%3CP%3E%2F%2F%20Allows%20AddItem%20operation%20using%20anonymous%20access%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eprivate%20static%20voidAllowAnonAccess()%7B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.WriteLine(%22Enabling%20Anonymous%20access....%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESPWebApplication%20webApp%20%3D%20SPWebApplication.Lookup(new%20Uri(webAppUrl))%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EwebApp.ClientCallableSettings.AnonymousRestrictedTypes.Remove(typeof(Microsoft.SharePoint.SPList)%2C%20%22GetItems%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EwebApp.ClientCallableSettings.AnonymousRestrictedTypes.Remove(typeof(Microsoft.SharePoint.SPList)%2C%20%22AddItem%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EwebApp.Update()%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.WriteLine(%22Enabled%20Anonymous%20access!%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%2F%2F%20Revokes%20Add%2FGet%20Item%20operation%20using%20anonymous%20access%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eprivate%20static%20voidRemoveAnonAccess()%7B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.WriteLine(%22Disabling%20Anonymous%20access....%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESPWebApplication%20webApp%20%3D%20SPWebApplication.Lookup(new%20Uri(webAppUrl))%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EwebApp.ClientCallableSettings.AnonymousRestrictedTypes.Add(typeof(Microsoft.SharePoint.SPList)%2C%20%22GetItems%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EwebApp.ClientCallableSettings.AnonymousRestrictedTypes.Add(typeof(Microsoft.SharePoint.SPList)%2C%20%22AddItem%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EwebApp.Update()%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EConsole.WriteLine(%22Disabled%20Anonymous%20access!%22)%3B%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%7D%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20do%20IISRESET%20after%20running%20this%20code%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20make%20use%20of%20the%20createListItem()%20and%20retrieveListItems()%20method%20discussed%20in%20the%20following%20articles%20to%20Add%2FGet%20items%20using%20the%20anonymous%20account%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%20How%20to%3A%20Retrieve%20List%20Items%20Using%20JavaScript%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fhh185007(v%3Doffice.14).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fhh185007(v%3Doffice.14).aspx%20%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%20Creating%20a%20List%20Item%20Using%20ECMAScript%20(JavaScript%2C%20JScript)%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fhh185011(v%3Doffice.14).aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fhh185011(v%3Doffice.14).aspx%20%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENote%3A%20If%20you%20are%20using%20a%20custom%20layouts%20page%20to%20execute%20the%20JS%20Script%2C%20make%20sure%20it%E2%80%99s%20accessible%20to%20the%20anonymous%20users.%20Inherit%20the%20custom%20page%20from%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmicrosoft.sharepoint.webcontrols.unsecuredlayoutspagebase.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20UnsecuredLayoutsPageBase%20%3C%2FA%3E%20with%20%3CA%20href%3D%22http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fmicrosoft.sharepoint.webcontrols.unsecuredlayoutspagebase.allowanonymousaccess.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20AllowAnonymousAccess%20%3C%2FA%3E%20set%20to%20true.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnonymous%20layouts%20page%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20244px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111498iEB47A9730C1A2EBE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EItem%20created%20by%20the%20anonymous%20user%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20244px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F111499i36607EC6FC484550%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESample%20code%20for%20this%20is%20available%20for%20download.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20anonymous%20access!!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmsdnshared.blob.core.windows.net%2Fmedia%2FTNBlogsFS%2Fprod.evol.blogs.technet.com%2Ftelligent.evolution.components.attachments%2F01%2F9350%2F00%2F00%2F03%2F57%2F87%2F28%2FAnonymous_List_Operations.zip%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%20Anonymous_List_Operations.zip%20%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-509832%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20TECHNET%20on%20Jun%2013%2C%202013%20This%20post%20is%20a%20contribution%20from%20Charls%20Tom%20Jacob%2C%20an%20engineer%20with%20the%20SharePoint%20Developer%20Support%20team.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-509832%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on TECHNET on Jun 13, 2013

This post is a contribution from Charls Tom Jacob, an engineer with the SharePoint Developer Support team.

 

This blog is based on a support ticket I handled recently. The requirement was to let anonymous users add items to a SharePoint list/library using client side object model(JavaScript).

 

Here are the steps needed to implement this.

 

1. Enable Anonymous access at the Web Application level

 

Go to SharePoint Central Administration => Application Management, select the Web Application => Authentication Providers, click on the zone, and select Enable anonymous access

 

 

2. Now, navigate to the corresponding web site, Site Action => Site Permissions => Anonymous Access.

 

Configure what anonymous users can access at the site level

 

 

3. Break the permission inheritance on the specific list in which you want to allow anonymous users to add items.

 

Navigate to the list/library settings for the list in which you want to allow Anonymous users to add items:

 

List Settings => Permissions for this list => Stop Inheriting Permissions, click OK => Anonymous Access

 

Select Add Items.

 

 

4. Enable “AddItem” operation for the client object model for the Web Application. You can run the following code as a console application (equivalent powershell script also should work).

 


// Allows AddItem operation using anonymous access


private static voidAllowAnonAccess(){


Console.WriteLine("Enabling Anonymous access....");


SPWebApplication webApp = SPWebApplication.Lookup(new Uri(webAppUrl));


webApp.ClientCallableSettings.AnonymousRestrictedTypes.Remove(typeof(Microsoft.SharePoint.SPList), "GetItems");


webApp.ClientCallableSettings.AnonymousRestrictedTypes.Remove(typeof(Microsoft.SharePoint.SPList), "AddItem");


webApp.Update();


Console.WriteLine("Enabled Anonymous access!");


}


// Revokes Add/Get Item operation using anonymous access


private static voidRemoveAnonAccess(){


Console.WriteLine("Disabling Anonymous access....");


SPWebApplication webApp = SPWebApplication.Lookup(new Uri(webAppUrl));


webApp.ClientCallableSettings.AnonymousRestrictedTypes.Add(typeof(Microsoft.SharePoint.SPList), "GetItems");


webApp.ClientCallableSettings.AnonymousRestrictedTypes.Add(typeof(Microsoft.SharePoint.SPList), "AddItem");


webApp.Update();


Console.WriteLine("Disabled Anonymous access!");


}

 

Please do IISRESET after running this code

 

You can make use of the createListItem() and retrieveListItems() method discussed in the following articles to Add/Get items using the anonymous account:

 

How to: Retrieve List Items Using JavaScript

 

http://msdn.microsoft.com/en-us/library/hh185007(v=office.14).aspx

 

Creating a List Item Using ECMAScript (JavaScript, JScript)

 

http://msdn.microsoft.com/en-us/library/hh185011(v=office.14).aspx

 

Note: If you are using a custom layouts page to execute the JS Script, make sure it’s accessible to the anonymous users. Inherit the custom page from UnsecuredLayoutsPageBase with AllowAnonymousAccess set to true.

 

Anonymous layouts page:

 

 

Item created by the anonymous user:

 

 

 

 

Sample code for this is available for download.

 

Happy anonymous access!!

 

Anonymous_List_Operations.zip