0

I have a sharepoint list with the folders option enabled. My goal is to save the items only inside the folders so that I could grant unique permissions on the folder rather than the item itself.

In the ItemAdding event receiver I want to check whether the user is trying to create the item inside a specific folder(in which case I'll just return from the receiver) or the user is trying to add the item in the root of the list(in which case I'll cancel the event).

I can't seem to find a way to retrieve the item's full Url. I've tried properties.AfterUl, HTTPContext/SPContext saved in the constructor,etc.

Any idea would be greatly appreciated.

Basically, I want a similar functionality as in this post, but for a list instead of a document library:

https://social.technet.microsoft.com/Forums/en-US/8cb4c3f5-0442-4a19-81b6-5fc16d683057/sharepoint-2010-can-we-check-parentfolder-in-beforeproperties-in-itemadding-event-handler?forum=sharepointgeneralprevious&prof=required

Many thanks, Adrian

0

This should get the folder itself

string itemFolder = properties.Web.GetFolder(properties.AfterUrl);

After that you should be able to get all the properties of an object type SPFolder including Url.

For Folder URL directly:

string itemFolderUrl = properties.Web.GetFolder(properties.AfterUrl).Url;
  • Thanks, but this doesn't work, properties.AfterUrl always returns empty string, - this is my problem I need to find a way to determine whether I am in the list's root or not. – Adrian Ganea Jun 22 at 14:03
  • Instead of itemAdding event receiver, try itemAdded. That will have all the fields properly populated and you can perform a recycle or delete on the item as needed – BigRaj Jun 22 at 14:58
  • Thanks, I try to avoid using ItemAdded and I will explain: I want specific users to add items only inside their own folders, on which unique permissions are set. If I use itemadded, for a small period of time (after the item has been added and until the event is finished) all other users will be able to see the item and this breaks my security requirements, even though the item would eventualy be deleted as you well mentioned. – Adrian Ganea Jun 22 at 15:22
0

I eventually managed to get the path using the referralurl from the httpcontext, however it doesn't work when using the quick edit.

Anyways, I found a better solution to fulfill my requirements: grant my users readonly permissions on the list and develop a custom action that uses elevated privilleges to create the folder and grant the necessary permissions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.