ArunDutt

Hi Everybody,

How can add values to a url field (url and description) through C# code
assigning "<a href=url>url</a>" is generating an error.

please help me

Arun



Re: SharePoint - Development and Programming Add values to url field

Pritam Dahake

The value for the URL field is stored in the following format : 'URL, Description '

For example if the url is http://www.google.com and the description is "Google" it would be stored as http://www.google.com, Google in the field value.

If you want to use the value in your C# code you will have to split the value string on ", "

If you want to populate the sharepoint URL field you will have to concatenate your URL and description field and then assign it to the value property of the SPField object.

Hope this helps.

-Pritam





Re: SharePoint - Development and Programming Add values to url field

ArunDutt

I have tried this, but the value I am assigning to listitem is coming as repeated with a coma seperation.
here I am giving my code.


private void AddNoteLink()
{
SPListItem currItem=SPContext.Current.ListItem;
currItem["fgh"] = "http://hello.com,help";
currItem.Update()
}

when i view the list it shows the value as
http://hello.com,,help, http://hello.com,help

I am assiging only once, but its coming as twice.

help me to find out the problem.





Re: SharePoint - Development and Programming Add values to url field

ArunDutt

Hi Pritam

thanks for the reply.

I couldnt find a property Value for the object SPField. Did you mean SPListItem

thanks and regards
Arun





Re: SharePoint - Development and Programming Add values to url field

el_Bacco



Hey Arun,

not exactly, but very close.

Try:
currItem["fgh"] = "http://hello.com , help";


or with a variable
currItem["fgh"] = "http://hello.com" + " , " + var;

fun have :-)




Re: SharePoint - Development and Programming Add values to url field

Pritam Dahake

Are you missing a space after the ","

The separator is ", " comma followed by a space and not just a comma

-Pritam