Anonymous Access to Add Items to Document Libraries

Update: A few days later a solution presented itself. Read about it here.

Long story short: I don’t think it can’t be done using the built-in list forms. If you can prove me wrong I will sing your praises to all who will listen.

Before writing the previous post in which I asked people to email me *shudder* their themes I tried to set up the document library to allow anonymous users to add new items to the library as you can do with most lists.

From the Settings Menu I chose Permissions for this Document Library:

And on the following screen I chose:

And finally I found myself on the screen where I could give anon the ability to add items to the list!

But alas!!! Thwarted again! Add, Edit, and Delete are all disabled.

Well, I don’t need no stinkin’ UI anyway. I’ll just use code.

SPSite site = new SPSite("http://www.elumenotion.com");

SPWeb web = site.OpenWeb("blog");

SPDocumentLibrary lib = (SPDocumentLibrary)web.Lists["Themes"];

lib.AnonymousPermMask64 = SPBasePermissions.ViewListItems | SPBasePermissions.OpenItems | SPBasePermissions.Open | SPBasePermissions.ViewFormPages | SPBasePermissions.AddListItems;

After running the code I go back to the list and:

Hooray! I win! There is an upload button. Let’s just test it shall we?

DOH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

After much experimenting I come to the conclusion that it just isn’t meant to be with a document library without creating some custom bits that don’t exclusively involve the list forms. I am hopeful that I can use impersonation to upload a file to a library via a user control or web part. But, I don’t have time for that any time soon.

So, maybe I could use an attachment on a custom list instead of a document library? Nope, same deal.

Author: Doug Ware