WSS Dev: HowTo Link to a List from a ListItem (Or HowTo contain Collections)

How can a ListItem contain a collection?
By having a field contining a link to another list.

Here is the ListItem in a list:

When you click on the Link1 link, you are redirected to List1.

Here is the ListItem in edit mode:

As you can see there are two ways to add links: In an enhanced RichText (Multiple Lines of text) field or in a Hyperlink field.

You can read the links with ForwardLinks:

      const string siteCollUrl = "http://my-site:31856/";
        //Test forward links:
        using (SPSite site = new SPSite(siteCollUrl))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList listSSS = web.Lists["List2"];
                SPListItem listItem = listSSS.Items[0];
                SPLinkCollection listLColl = listItem.ForwardLinks;
                string test = listItem.ForwardLinks[0].Url;
            }
        }

 Thanx to Peter Karpinski

Have fun.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: