1

I want to get all pages from pages library from search result where page layout name is "abc.aspx". I have tried below code but it is not working. If I simply pass "abc" in querytext then it will get result from list,library and from every where. I want to get only those pages whose page layout is "abc.aspx". How to do that?

string pageLayoutFullName="abc.aspx"
  KeywordQuery keywordQueryTop = new KeywordQuery(site);
  keywordQueryTop.SelectProperties.Add("Title");
  keywordQueryTop.SelectProperties.Add("PublishingPageLayoutOWSURLH");
  keywordQueryTop.SelectProperties.Add("WebId");
  keywordQueryTop.SelectProperties.Add("ModifiedOWSDATE");
  keywordQueryTop.RowLimit = 15;
  keywordQueryTop.ResultsProvider = SearchProvider.SharepointSearch;
  keywordQueryTop.QueryText = String.Format("PublishingPageLayoutOWSURLH=\"*{0}\"", pageLayoutFullName);
4
  • The problem you have is because SharePoint search does not support suffix-matching (*omething), only prefix-matching (somethin*). Try to add the full URL to the page layout, or look for another managed property containing only for examle the name of the layout Commented Aug 4, 2014 at 13:38
  • I could not find another useful managed propery for you unfortunately. Are the pages from only one site collection? Then you can use the full path http://portal.com/_catalogs/masterpage/PageLayoutFileName.aspx, PageLayoutName. If not, it seems more difficult! Commented Aug 4, 2014 at 13:46
  • Another approach would be to use a unique content type for this page layout - then instead of querying for page layout name you could query for content type which will work just fine. msdn.microsoft.com/en-us/library/office/…
    – Robin
    Commented Aug 4, 2014 at 18:04
  • Yupp, the content type approach seems to be the only viable one in this scenario (as mentioned last in my answer) Commented Aug 5, 2014 at 6:07

1 Answer 1

1

The problem you have is because SharePoint search does not support suffix-matching (*omething), only prefix-matching (somethin*). Therefore this row will not work

keywordQueryTop.QueryText = String.Format("PublishingPageLayoutOWSURLH=\"*{0}\"", pageLayoutFullName);

Are the pages from only one site collection? Then you can use the full path http://portal.com/_catalogs/masterpage/PageLayoutFileName.aspx, PageLayoutName.

If not, it seems more difficult!

There is a crawled property named "ows_PublishingPageLayout", try mapping that one up to a new Managed Property, perform a full crawl and see what you get from that property (you can use the REST API in the browser to test it:

http://portal.com/_api/search/query?querytext='*'&selectproperties='PublishingPageLayout'

Update

Unfortunately, this property also indexes the URL, not the name:

<d:Key>PublishingPageLayout</d:Key> 
<d:Value>http://portal.com/_catalogs/masterpage/PageLayoutFileName.aspx</d:Value> 

which is not helpful for you. I find no other properties that seems to be useful, so you might be out of luck I'm afraid (if the specific Page Layout does not use a specific custom content type).

5
  • In one web application I have have page layout and pages. Pages are also in variance site in English and German. Commented Aug 5, 2014 at 5:48
  • In one web application I have page layout and pages. Pages are also in variance site in English and German. In another web application I have to display that result from search.Now I can not pass complete URL. Commented Aug 5, 2014 at 6:11
  • Are the page layout using a custom content type, or containing some field specific for this page layout? I think that is your only way around Commented Aug 5, 2014 at 6:36
  • Page layout is using custom content type Commented Aug 7, 2014 at 5:21
  • But from one content type multiple page layout is created. Commented Aug 7, 2014 at 5:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.