Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I had to realize a Custom Field to show when the associated Item has broken role inheritance...

I see 2 ways to do that:

  • Read just in time if the Item has broken role inheritance
  • Derive a Boolean SP Field and keep the value inside of it

I think the first way is more efficent (also because I must not implement an Event Handler on Item Check In or something like that)...

How can I access to the SPListItem from a custom field? Is there any method or suggested practice?

Thank you very much!!

share|improve this question
add comment

1 Answer

The custom field basically uses BaseFieldControl to show field value. This class has two templates for control rendering - DefaultTemplateName (for new/edit form) and DisplayTemplateName (for display form). You can try to create these templates and override Value method of BaseFieldControl. In this method you should have access to the Item property of BaseFieldControl. If the microsoft documentation is correct this property provides SPItem object that has HasUniqueRoleAssignments flag for indicating whether the object has unique role assignments or inherits its role assignments from a parent object.

For example:

public override object Value
{
    get
    {
        _control = TemplateContainer.FindControl("controlId");
        _control.Visible = Item.HasUniqueRoleAssignments;

        return null;
    }
    set
    {
        base.Value = value;
    }
}
share|improve this answer
    
This works with the BaseFieldControl, but I need it during the display in listviewwebpart.. –  Ziba Leah Jul 9 '12 at 14:51
    
it is much easier. Look this post. You can use the same approach. –  Alexander Jul 9 '12 at 18:38
    
Yes it's the way I follow to create it... But now I have a boolean value and I modify it whenever I modify the permission on the file by 2 custom ribbon actions... I can't face how I can get the item from the SPFieldText that I'm extending without using the BaseFieldControl item –  Ziba Leah Jul 10 '12 at 9:01
1  
If I understand correctly, in your case the best way is to use class that is inherited from SPFieldBoolean class. This field should be set from code by your custom actions. For this field you can set BaseFieldControl and use _control.Visible = value. if you need to customize list view you can use Glyn post. In your xsl your should check boolean value of this field and show or not labels. –  Alexander Jul 10 '12 at 10:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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