2

I'm creating a custom field that stores multiple link inside. The user control works, but it shows me the link like text so now I'm overloading the GetFieldValueAsHtml to modify the HTML..

How can I write down my link as SPLink? Every SPLink Properties is "readonly", so i can't understand HOW to do that!

I'd like to do something like that:

public override string GetFieldValueAsHtml(object value)
{

    string[] address= base.GetFieldValueAsText(value).Split(';');

    foreach (string s in address)
    {
        SPLink link = new SPLink();
        /*
         * MODIFY LINK
         * */
        this.FieldRenderingControl.Controls.Add(link);
    }

    //Code to convert in HTML my Control
}
0

I think all you need to do in this method is provide a string representation of your field.

You do not need to add a control to controls collection. Sharepoint just takes the your string (html encoded) and puts on the web page. The string representation can be built by StringBuilder class.

  • Ok.. So you're telling me to add some "<a href...>" inside the string returned... But if i solve this problem this way everyone can see the links.. The thing i want to do is to swho only the link accessible for the logged in user! I guess SPLink could do that automatically! – Ziba Leah Nov 22 '11 at 8:29
  • Returning HTML code it prints it as is, no rendering as been applied!!! =/ – Ziba Leah Nov 22 '11 at 9:17
  • If you want to do security trimming, you will need to do this yourself. I doubt using SPLink will automatically perform the security trimming for you. In fact SPLink isn't a control, so your code above shouldn't even compile. – Paul Lucas Nov 22 '11 at 10:57
  • Use SPHttpUtility.HtmlEncode method to return HTML encoded string as I stated above. – Ashish Patel Nov 22 '11 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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