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

in a custom ListDefinition I used a calculated field to format a Text into an URL. I'm developping in VisualStudio2010 for SP2010.

Here is my ListDefinition:

<Fields>
      <Field Name="DocumentLink" StaticName="DocumentLink" DisplayName="Dokumentenlink" Type="Text"
         ID="8E434824-3230-493D-86B0-A60BABC56672"/>
  <Field Name="LinkType" StaticName="LinkType" DisplayName="Linktyp" Type="Choice" Format="RadioButtons"
         ID="D6A6880E-DF32-4A15-B5CC-1ABFA88EF2F4" >
    <CHOICES>
      <CHOICE>HTTP</CHOICE>
      <CHOICE>Datei/Ordner</CHOICE>
    </CHOICES>
  </Field>
  <Field Name="DocumentPath" StaticName="DocumentPath" DisplayName="DocumentPath" Type="Calculated"
         LCID="1031" ResultType="Text"
         ID="3957EA2D-5E88-477D-B801-27A51B5599C2" >
    <Formula>=IF(LinkType="Datei/Ordner", CONCATENATE("file:///", DocumentLink), DocumentLink)</Formula>
    <FieldRefs>
      <FieldRef Name="LinkType" />
      <FieldRef Name="DocumentLink" />
    </FieldRefs>
  </Field>
</Fields>

in my View the Field is displayed as Text, but in the DisplayForm it's (like i expect it) displayed as hyperlink.

My ViewFields are not complicated, so I would guess this isn't the failure

    <ViewFields>
      <FieldRef Name="LinkTitle"></FieldRef>
      <FieldRef Name="DocumentPath" Format="Hyperlink" CreateURL="TRUE" TextOnly="FALSE" >
      </FieldRef>
      <FieldRef Name="Describtion" ></FieldRef>
    </ViewFields>

Tried solutions: -Adding a Computed Field with DisplayPattern. -Formula which calculates the FieldValue in HTML-tags (value) Alternative formula:

<Formula>
      =IF(LinkType="Datei/Ordner",
      CONCATENATE("&#60;DIV&#62;&#60;A href='file:///", DocumentLink, "' &#62;", DocumentLink, "&#60;/A&#62;&#60;/DIV&#62;"),
      CONCATENATE("&#60;DIV&#62;&#60;A href='", DocumentLink, "' &#62;", DocumentLink, "&#60;/A&#62;&#60;/DIV&#62;"))
</Formula>

Thanks for your help in advance.

share|improve this question
    
How do you render your view? –  Christophe Jul 25 '12 at 5:24
    
Standard, in the View I changed only the FieldRefs. –  Maikm88 Jul 25 '12 at 7:12

3 Answers 3

You could try to use the disable-output-escaping attribute in your XSLT.

You'll find some more explanations in this blog post:

http://blog.pathtosharepoint.com/2009/07/26/html-calculated-column-and-data-view-web-part/

share|improve this answer
up vote 1 down vote accepted

Thanks you for the suggestions. Here's the working solution: I had to create a xsl:stylesheet for the field. (The View stayed as before). The xsl I had to deploy in the sp-folder

"{SharePointRoot}\Template\LAYOUTS\XSL" My Template looks like this:

<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[@Name='DocumentPath']" mode="Text_body">
    <xsl:param name="thisNode" select="."/>
    <xsl:text disable-output-escaping="yes">&lt;a href="</xsl:text>
    <!--explicit link value-->
    <xsl:value-of select="$thisNode/@DocumentPath" disable-output-escaping="yes" />
    <xsl:text disable-output-escaping="yes">" &gt;</xsl:text>
    <!--short field value, without the file:/// text in case of file/dir-link-->
    <xsl:value-of select="$thisNode/@DocumentLink" disable-output-escaping="yes" />
    <xsl:text disable-output-escaping="yes">&lt;/a&gt;</xsl:text>
  </xsl:template>
</xsl:stylesheet>

I hope someone else could make profit of this solution.

share|improve this answer

If you want to avoid making XSL changes, you could try out my company's free HTML Calculated Column.

Here's my recent article on using it to create links that open in a new window:

Pentalogic: Opening a URL in a new Window from a SharePoint list

share|improve this answer

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.