Finding Pages By Additional Urls with Fluent API

Posted by Community Admin on 04-Aug-2018 14:53

Finding Pages By Additional Urls with Fluent API

All Replies

Posted by Community Admin on 02-Oct-2013 00:00

HI,
I'm running into an issue where I cannot add an additional URL for a page because that additional url already exists on another page. 

I'm looking to find this other page programmatically. 

I am developing for Sitefinity 5+ and want to use the Fluent API

I have tried modifying the code on the Developer Documentation without success ( www.sitefinity.com/.../querying-pages

I was hoping to use something like this: 

01.string urlName = "~/productsandservices";
02. 
03.        PageData pageData = null;
04. 
05.        var count = 0;
06.        App.WorkWith().Pages().Where(pN => pN.Urls.Contains(urlName)).Count(out count);
07. 
08.        if (count != 0)
09.        
10.            pageData = App.WorkWith().Pages().Where(pN => pN.Urls.Contains(urlName)).Get().First().Page;
11.            Response.Write(pageData.Title.ToString());
12.        
13.        else
14.        
15.            Response.Write( "\"" + urlName + "\"" + " Not Found");
16.        

However, that introduces a type error, where pN.Urls.Contains(...) expects a PageUrlData item. I attempted to rectify this by defining my own PageUrlData item and assigning the 'Url' property to 'urlName' like so:

01.string urlName = "~/productsandservices";
02. 
03.PageData pageData = null;
04. 
05.PageUrlData pageUrlData = new PageUrlData();
06.pageUrlData.Url = urlName;
07. 
08.var count = 0;
09.App.WorkWith().Pages().Where(pN => pN.Urls.Contains(pageUrlData)).Count(out count);
10. 
11.if (count != 0)
12.
13.    pageData = App.WorkWith().Pages().Where(pN => pN.UrlName == urlName).Get().First().Page;
14.    Response.Write(pageData.Title.ToString());
15.
16.else
17.
18.    Response.Write( "\"" + urlName + "\"" + " Not Found");
19.

However, this code always returns a count of 0. So, I must be doing something wrong. 

I think my problems in my custom definition of pageUrlData; however, I do not know how to fix it. 

Can anyone point out what I'm missing, and how to go about correcting it?

Thank you

Posted by Community Admin on 14-Oct-2013 00:00

Guess not.

Posted by Community Admin on 17-Oct-2013 00:00

Hi,

Would it be possible to try the following approach with the native API:

var addUrl = new PageUrlData();
           addUrl.Url = "~/productsandservices";
            
           PageManager pageManager = PageManager.GetManager();
           var pages = pageManager.GetPageNodes();
           foreach (var page in pages)
           
               var urls = page.Urls;
               foreach (var url in urls)
               
                   var present = url.Url == "~/productsandservices";
               
           
 

Regards,
Atanas Valchev
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed