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

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
}
share|improve this question
    
I'm not sure so I'm posting a comment.. but couldn't you just use a HyperLink and set the Text and NavigateURL properties? msdn.microsoft.com/en-us/library/… –  Kit Menke Nov 21 '11 at 17:38
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
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
add comment

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.