November Happy Hour will be moved to Thursday December 5th.

obtain PageReference from linkcollection item

Vote:
 

I need to read properties from the pages added to a Link Colection

Any ideea how could I obtain a reference to each page in a Link Collection property?

I have the link to the page in the LinkItem object how can i use it or maybe if there is any other way please let me know

 


#27021
Jan 14, 2009 12:56
Vote:
 

Hi,

 If the LinkItem.Href is not a friendly url, I suppose you could substring it and get the id?

#27028
Jan 14, 2009 16:01
Vote:
 
I've never used the LinkCollection, but if you have a URL you can parse it by PageReference.ParseUrl(...);
#27032
Jan 14, 2009 17:32
Vote:
 

or by
PageReference res = PermanentLinkUtility.GetPageReference(new UrlBuilder(url));

If you use Itera.MultiProperty you can loop over the item like this:

<Itera:Property ID="Property2" runat="server" PropertyName="LinksRelaterte.Links" SuppressEmpty=false >
    <ItemTemplate>
        <p>
            {this.ToMappedLink}
            Href={this.Href}<br />
            PageReference={this.Href.ToPageData()}<br />
            PageLink={this.Href.ToPageData().LinkURL}<br />
            PageName={this.Href.ToPageData().PageName}<br />
           
           Text={this.Text}<br />
           Target={this.Target}<br />
        </p>
    </ItemTemplate>
</Itera:Property>

This will generate output like:
The Norwegian Embassy, Tokyo Href=~/link/f4fb6b10a78c425fbf4febf6830bd8af.aspx?epslanguage=en
PageReference=6311
PageLink=/Templates/Public/Pages/Page.aspx?id=6311&epslanguage=en
PageName=Information
Text=The Norwegian Embassy, Tokyo
Target=

#27033
Edited, Jan 14, 2009 18:37
Vote:
 

thanks for the answers

my solution was to get the GUID of the page in order to use this

PermanentLinkUtility.FindPageReference(new Guid(sGuid)) 

but this was a temporary solution, i really wanted to use 

PageReference res = PermanentLinkUtility.GetPageReference(new UrlBuilder(url)); 

where url i thought it would be the  LinkItemCollection.LinkItem.Href but this didn't worked as expected

I am using LinkItemCollection and the target objects are LinkItem objects

It would be nice if there was a method like in your example : Href.ToPageData()

 

#27048
Jan 15, 2009 11:50
Vote:
 

Also PageReference.ParseUrl is not helping i get a pagereference with ID 0  every time

The LinkItem.href looks something like this ~/Link/SomeGuid.aspx

#27049
Jan 15, 2009 11:55
Vote:
 

Hello.

Maybe this answer comes a little bit late, but I think I have found a small solution to this. The I found the secret solution in the method:  PermanentLinkMapStore.TryToMapped(linkItem.Href, out selectedOutPutString);

 So what I did for short was to first get the PropertyLinkCollection, then started to loop through all the LinkItems. My purpose was only to get hold of the pages and not documents, external links, but these could easily also be handled. See my solution below:

 

// Create a new PageDataCollection
            PageDataCollection indexPages = new PageDataCollection();

            // Get the property
            PropertyLinkCollection propertyIndexPages = CurrentPage.Property["IndexPages"] as PropertyLinkCollection;
            // Make sure it is not null
            if (propertyIndexPages != null)
            {
                
                // Loop through all the links in the property
                foreach (LinkItem link in propertyIndexPages.Links)
                {
                    // Create the output strin
                    string linkUrl = string.Empty;
                    // Try to map the link
                    PermanentLinkMapStore.TryToMapped(link.Href, out linkUrl);
                    // Make sure there is a link, Externa urls will not be mapped, but documents will.
                    if (!string.IsNullOrEmpty(linkUrl))
                    {
                        // Try to cast to a PageReference
                        PageReference pageRef = PageReference.ParseUrl(linkUrl);
                        // In this case only add Pages, you could here also handle documents
                        if(!PageReference.IsNullOrEmpty(pageRef))
                            indexPages.Add(GetPage(pageRef));
                    }
                }
            
            }

 

 

Hope this could help a little bit.

regards

gustaf 

#27833
Feb 10, 2009 10:51
Vote:
 

thanks gustaf.

your little piece of code helped me out.

sweet as!

#29554
May 04, 2009 19:37
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.