0
votes

I have a Sharepoint custom field with a custom string property. It works perfectly, i can set the property by my custom custom control and the value is stored. I want to to customize the field rendering in list view using my XSL file and according to the value of the custom property.

How can i get this value?

[EDIT] This is the field xml defintion:

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
  <FieldType>
    <Field Name="TypeName">Secure</Field>
    <Field Name="ParentType">Text</Field>
    <Field Name="TypeDisplayName">Secure</Field>
    <Field Name="TypeShortDescription">Secure Field</Field>
    <Field Name="UserCreatable">TRUE</Field>
    <Field Name="ShowOnListCreate">TRUE</Field>
    <Field Name="ShowOnSurveyCreate">TRUE</Field>
    <Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
    <Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
    <Field Name="Sortable">FALSE</Field>
    <Field Name="Filterable">FALSE</Field>
    <Field Name="FieldTypeClass">MyProject.SecureFields.SecureField, $SharePoint.Project.AssemblyFullName$</Field>
    <Field Name="FieldEditorUserControl">/_controltemplates/SecureFieldPropertyEditor.ascx</Field>
    <PropertySchema>
      <Fields>
        <Field Name="ShowedFieldName" Hidden="TRUE" DisplayName="ShowedFieldName" Type="Text" MaxLength="255">
          <Default></Default>
        </Field>
      </Fields>
    </PropertySchema>
  </FieldType>
</FieldTypes>

And this is the XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
                xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
                version="1.0"
                exclude-result-prefixes="xsl msxsl ddwrt"
                xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
                xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
                xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:SharePoint="Microsoft.SharePoint.WebControls"
                xmlns:ddwrt2="urn:frontpage:internal">

  <xsl:template match="FieldRef[@FieldType = 'Secure']" mode="Text_body">
    <xsl:param name="thisNode" select="." />
    <xsl:variable name="showedFieldName" select="./@*[name()=current()/@ShowedFieldName]" />
    <span style="background-color:lightgreen;font-weight:bold">
      <xsl:value-of select="$showedFieldName"/>      
    </span>
  </xsl:template>

</xsl:stylesheet>
2

2 Answers

2
votes

iam crazy from lack of MS guys and MSDN documentation. Maybe this help, worked for my Custom Field Type (Custom property named LinkType):

    <xsl:template match="FieldRef[@FieldType = 'EnhancedTitleField']" mode="Text_body">

    <xsl:param name="thisNode" select="."/>
    <xsl:variable name="linkType" select="$thisNode/@LinkType" />
    <xsl:choose>
      <xsl:when test="$linkType=''">
        empty
      </xsl:when>
      <xsl:otherwise>
        link
      </xsl:otherwise>
    </xsl:choose>


  </xsl:template >

... Later, after hours of testing maybe founded solution. When I inherit my field from "SPFieldMultiLineText", owerride "GetFieldValueAsHtml" and change field definitio it starts working. Here is key code of working combination:

<Field Name="ParentType">Note</Field>
<Field Name="CAMLRendering">TRUE</Field>
<Field Name="AllowBaseTypeRendering">TRUE</Field>

<RenderPattern Name="DisplayPattern">
  <Column Name="ID" /><HTML><![CDATA[;]]></HTML><Column Name="Title" /><HTML><![CDATA[;]]></HTML><PageUrl WebRel="FALSE" URLEncode="TRUE"/>
</RenderPattern>

In code:

EnhancedTitleField : SPFieldMultiLineText

...

public override string GetFieldValueAsHtml(object value)
{

    string[] splitedValue = value != null ? value.ToString().Split(';') : new string[0];

    int id = splitedValue.Length > 0 ? int.Parse(splitedValue[0]) : 0;
    string title = splitedValue.Length > 1 ? splitedValue[1] : "";
    string source = splitedValue.Length > 2 ? splitedValue[2] : "";

    string html = EnhancedTitleFieldControl.GetHtml(this, id, title, source);

    return html;
}

Somehow in SPFieldMultilinetext CAML generated value is passed to this method. So you can prepair context data from caml for processing in this method where you HAVE ACCESS to CUSTOM PROPERTIES!

Hope this helps :), and MS guys, DO SOMETHING with MSDN documentation!

0
votes

Can you give us some more information about your structure?! But of course yuo could try to use if else conditions on your custom field.