Wednesday, May 27, 2015

SharePoint Tips: http://www.sharepoint-tips.com/

I found a good SharePoint knowledge blog http://www.sharepoint-tips.com/  SharePoint-tips and learning.

 

 

SharePoint: Finding if a site column exists in a site, by ID

Scenario - you have an ID of a site column (SPField belonging to SPWeb)and you want to find out if there is a field by that ID in the collection.

Problem: if you try something like:

web.Fields[fieldID] == null


The result is an exception if the field doesnt exist. What a shame. 

The solution is to use the Contains method of the Fields collection:

web.Fields.Contains(fieldID)



 

SharePoint: Users able to open documents using links, even without permissions

Users able to open documents using links, even without permissions

Recently I had to troubleshoot an issue where end-users were able to open links to documents they had no permissions to open. If they tried opening the library they got the "access denied" message that is expected, but clicking a link directly to a document in the library resulted in the document either opening up in the browser, or downloaded. We double checked the documents did not have item level security, and they didn't.

What a puzzle!

Turns out that those libraries were provisioned by code, and the code set a property on the library called "AllowEveryoneViewItems" (msdn documentation). This property, when set to true, means that anyone- even unauthenticated users, will be able to download and view items in the list or library - even without permissions. 

The reason to turn it to true is when dealing with anonymous sites - for example, if you have an internet site and you want to put links to documents from pages, but you don't want users to be able to browse the library itself.