I have a custom field for storing an attachment name. I'm trying to display url for this attachment on list view instead of just the name.
I've tried to overide GetFieldValue in field definition class, but I couldn't find any way to get item id required to generate url.
public override object GetFieldValue(string value)
{
var id = ((ARPFileFieldControl)FieldRenderingControl).ListItem.ID;
string html = String.Format("<a href=\"{0}\">{1}</a>", String.Format("Attachments/{0}/{1}", id, value), value);
return base.GetFieldValue(html);
}
This works only when I click the item on list view. When page loads it throws exception because ListItem is not initialized.
I've tried to create custom xsl to do the job, but also without success.
<xsl:template match="FieldRef[@FieldType='Field Uploader']" mode="body" >
<xsl:param name="thisNode" select="." />
<a href="{$RootSiteUrl}/Attachments/{$thisNode/@ID}/{$thisNode/@*[name()=current()/@Name]}"><xsl:value-of select="$thisNode/@*[name()=current()/@Name]" /></a>
</xsl:template >
When I try to match field by ID it works fine, but that's not an option because I use this field multiple times and want it to be used in future without changing code every time someone adds new list.
Are there any other ways I can achieve this?