Guest User

Untitled

a guest
Apr 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <%@ Page Language="c#" AutoEventWireup="true" Debug="true" %>
  2. <%@ Import Namespace="Sitecore.Data.Items" %>
  3.  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  5. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html>
  7. <head>
  8. <title>List of URLs</title>
  9. </head>
  10. <body>
  11. <script language="C#" runat="server">
  12.  
  13. string domain = "http://mysite.com";
  14. int count = 0;
  15.  
  16. void Page_Load(object sender, System.EventArgs e)
  17. {
  18. Sitecore.Data.Database web = Sitecore.Configuration.Factory.GetDatabase("web");
  19.  
  20. var home = web.GetItem("/sitecore/content/MySite/home");
  21.  
  22. var pages = GetChildren(home);
  23.  
  24. Response.Write(pages);
  25. Response.Write("Total # of pages: " + count.ToString());
  26.  
  27. }
  28.  
  29. private string GetChildren(Item home)
  30. {
  31. string result = "";
  32. if (!home.HasChildren) return "";
  33.  
  34. var childList = home.GetChildren();
  35. foreach(Item item in childList)
  36. {
  37. if (DoesSitecoreItemHavePresentation(item))
  38. {
  39. result += domain + Sitecore.Links.LinkManager.GetItemUrl(item) + "<br />";
  40. count++;
  41. }
  42.  
  43. result += GetChildren(item);
  44. }
  45.  
  46. return result;
  47. }
  48.  
  49. public bool DoesSitecoreItemHavePresentation(Item item)
  50. {
  51. return item.Fields[Sitecore.FieldIDs.LayoutField] != null
  52. && item.Fields[Sitecore.FieldIDs.LayoutField].Value != String.Empty;
  53. }
  54.  
  55. </script>
  56. </body>
  57. </html>
Add Comment
Please, Sign In to add comment