2009-06-15 12 views

Respuesta

7

Que yo sepa, no está disponible en la plataforma estándar. Lo que puede hacer por el contrario es a su propio artesanal fieldcontrol

Así que en fieldtypes.xml encargo

<FieldTypes> 

    <FieldType> 
    <Field Name="TypeName">MyInteger</Field> 
    <Field Name="ParentType">Integer</Field> 
    ... 
    <Field Name="FieldTypeClass">xxx</Field> 
    </FieldType> 

y en sitecolumns.xml

<Field ID="xxx" 
     Name="xxx" 
     DisplayName="xxx 
     Description="xxx" 
     Group="xxx 
     Type="MyInteger"  
     DisplaceOnUpgrade="TRUE" 
    /> 

y en su fieldcontrol

public class MyInteger: SPFieldNumber 
{ 
    public MyInteger(SPFieldCollection fields, string fieldName) 
     : base(fields, fieldName) 
    { 
    } 

    public MyInteger(SPFieldCollection fields, string typeName, string displayName) 
     : base(fields, typeName, displayName) 
    { 
    } 


    public override BaseFieldControl FieldRenderingControl 
    { 
     [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)] 
     get 
     { 
      Microsoft.SharePoint.WebControls.BaseFieldControl ctl = 
       new MyIntegerControl(); 
      ctl.FieldName = InternalName; 
      return ctl; 

     } 
    } 

    } 

y en MyIntegerControl puede hacer lo que quiera (muchas anulaciones), pero un ejemplo Le es:

protected override void CreateChildControls() 
{ 
    base.CreateChildControls(); 
    if (this.ControlMode == SPControlMode.New || 
     this.ControlMode == SPControlMode.Display) 
    { 
     // check that use is admin and display value 
    } 
} 
+0

Estoy de acuerdo que una costumbre el campo es el camino a seguir. Excelente ejemplo! –

+0

Yo también, y muy bien presentado ejemplo! – Colin

0

También puede hacer este registro por un CustomAction, y cambiar la vista de lista esquema dinámico

 <CustomAction Id="CustomAction" 
      GroupId="SiteActions" 
      Location="Microsoft.SharePoint.StandardMenu" 
      Sequence="1003" 
      ControlAssembly="$SharePoint.Project.AssemblyFullName$" 
     ControlClass="CustomAction.ColumnPermissionAction"/> 

y en su clase de control:

class ColumnPermissionAction : Control 
{ 
    protected override void OnLoad(EventArgs e) 
    { 
     base.OnLoad(e); 
     HideColumn(); 
    } 

    private HideColumn(){ 
     WebPart part=//find your web part 
     string colName="SecretColumn"; 
     if(part is ListViewWebPart){ 
      (part as ListViewWebPart).ListViewXml = (part as ListViewWebPart).ListViewXml.Replace(string.Format("<FieldRef Name=\"{0}\"/>", colName), string.Empty); 
     }else if(part is XsltListViewWebPart){ 
      PropertyInfo property = typeof(DataFormWebPart).GetProperty("ListViewXmlDom", BindingFlags.NonPublic | BindingFlags.Instance); 
      if (property != null) 
      { 
       XmlNode xmlView = property.GetValue(part as XsltListViewWebPart, null) as XmlNode; 
       if (xmlView != null) 
       { 
        XmlNode node = xmlView.SelectSingleNode("//ViewFields"); 
        if (node != null) 
        { 
          var field = node.SelectSingleNode(string.Format("FieldRef[@Name='{0}']", colName)); 
          if (field != null) 
          { 
           node.RemoveChild(field); 
          } 
        } 
       } 
      } 
     } 
    } 
} 
Cuestiones relacionadas