protected override void CreateChildControls() { base.CreateChildControls(); SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite site = new SPSite(SPContext.Current.Site.ID)) { var rootWeb = site.RootWeb; root = ReadSiteStructure(rootWeb); HtmlGenericControl control = new HtmlGenericControl("ul"); control.Attributes.Add("id", RootId); control.Attributes.Add("class", "treeview"); foreach (var item in root.ChildItems) { AddChildControl(control, item, 0, root.ChildItems[root.ChildItems.Count - 1] == item); } this.Controls.Add(control); } }); }
private SiteMapItem GetFolderStructure(DirectoryInfo dir, string rootPath, int level) { var siteMapItem = new SiteMapItem { name = dir.Name.Replace("-", " "), path = dir.FullName.Substring(rootPath.Length).Replace('\\', '/'), level = level, sort = GetSort(dir.Name, level) ?? 100 }; if (dir.GetDirectories().Any() == false) { return(siteMapItem); } var list = new List <SiteMapItem>(); foreach (var child in dir.GetDirectories().Where(x => x.Name != "images")) { list.Add(GetFolderStructure(child, rootPath, level + 1)); } siteMapItem.hasChildren = true; siteMapItem.directories = list.OrderBy(x => x.sort).ToList(); return(siteMapItem); }
private void AddChildControl(HtmlGenericControl control, SiteMapItem root, int level, bool isLast) { HtmlGenericControl li = new HtmlGenericControl("li"); control.Controls.Add(li); if (isLast) li.Attributes.Add("style", "li_last"); HtmlGenericControl a = new HtmlGenericControl("a"); a.Attributes.Add("class", "level_"+(level+1).ToString()); a.Attributes.Add("href", root.Url); a.InnerText = root.Title; li.Controls.Add(a); if (root.ChildItems != null && root.ChildItems.Count > 0) { li.Attributes.Add("class", "submenu"); // li.Attributes.Add("style", "background-image: url('/Style Library/images/open.gif');"); if (root.ChildItems != null) { HtmlGenericControl ul = new HtmlGenericControl("ul"); foreach (var item in root.ChildItems) { //ul.Attributes.Add("rel", "closed"); //ul.Attributes.Add("style", "display:block"); li.Controls.Add(ul); int childLevel = level + 1; AddChildControl(ul, item, childLevel, item== root.ChildItems[root.ChildItems.Count-1]); } } } }
private static string RenderMenu(SiteMapItem item) { if (!item.IsMenuVisible) { return(string.Empty); } var html = string.Empty; var hasChildren = item.Children.Any(c => c.IsMenuVisible); var cssClasses = new List <string>(); if (hasChildren) { cssClasses.Add("toggle"); } if (item.IsActive || item.Children.AnyRecursive(m => m.IsActive)) { cssClasses.Add("expanded"); } if (item.IsActive) { cssClasses.Add("active"); } html += string.Format("<li class=\"{0}\">", string.Join(" ", cssClasses)); html += "<div class='menu-item-container'>"; if (!string.IsNullOrEmpty(item.IconCssClass)) { html += string.Format("<i class=\"menu-icon {0}\"></i>", item.IconCssClass); } html += string.Format("<a class='menu-link' href=\"{0}\">{1}</a>", item.Url, item.Title); html += "<i class='menu-toggle-icon'></i>"; html += "</div>"; if (hasChildren) { html += "<ul>"; html = item.Children.Aggregate(html, (current, childMenu) => current + RenderMenu(childMenu)); html += "</ul>"; } html += "</li>"; return(html); }
// POST: Admin/UpdateConf public ActionResult UpdateSitemapXML() { UrlHelper urlHelper = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext); List <SiteMapItem> list = new List <SiteMapItem>(); list.Add(new SiteMapItem(urlHelper.QualifiedAction("Index", "Home"))); list.Add(new SiteMapItem(urlHelper.QualifiedAction("Video", "Home"))); list.Add(new SiteMapItem(urlHelper.QualifiedAction("Index", "Article"))); List <ArticlesViewModel> model = new List <ArticlesViewModel>(); using (var context = new SiteDbContext()) { model = context.Articles .Where(r => r.PublishState == 2) .OrderByDescending(r => r.Id) .Select(r => new ArticlesViewModel { Id = r.Id, Title = r.Title, Date = r.Date, Views = r.Views, PublishState = r.PublishState }).Take(25).ToList(); } foreach (var article in model) { SiteMapItem itemmap = new SiteMapItem(Request.Url.Host + "/Article/Detail/" + HttpUtility.UrlEncode(article.Title), article.Date, ChangeFrequency.Weekly, 0.5); list.Add(itemmap); } EasySiteMapGenerator g = new EasySiteMapGenerator(new SiteMapConfig() { Domain = Request.Url.Host + "/", LocalFile = Server.MapPath("~"), TotalItensByFile = 50000 }); g.GenerateSiteMap(list); Response.StatusCode = (int)System.Net.HttpStatusCode.OK; return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); }
private SiteMapItem ReadSiteStructure(SPWeb web) { SiteMapItem node = new SiteMapItem() { Title = web.Title, Url = web.Url }; if (web.Webs != null && web.Webs.Count > 0) { node.ChildItems = new List <SiteMapItem>(); foreach (SPWeb subWeb in web.Webs) { node.ChildItems.Add(ReadSiteStructure(subWeb)); } } return(node); }
private SiteMapItem GetSiteMapItem(SiteContent content, List <SiteContent> contents) { var item = new SiteMapItem() { SiteContentID = content.SiteContentID, SiteContentParentID = content.SiteContentParentID, Title = content.Title, Url = content.Permalink, IconCssClass = content.MenuIconCssClass, IsMenuVisible = content.MenuVisible }; foreach (var childItem in contents.Where(s => s.SiteContentParentID == content.SiteContentID).Select(child => GetSiteMapItem(child, contents))) { item.Children.Add(childItem); } return(item); }
private void AddChildControl(HtmlGenericControl control, SiteMapItem root, int level, bool isLast) { HtmlGenericControl li = new HtmlGenericControl("li"); control.Controls.Add(li); if (isLast) { li.Attributes.Add("style", "li_last"); } HtmlGenericControl a = new HtmlGenericControl("a"); a.Attributes.Add("class", "level_" + (level + 1).ToString()); a.Attributes.Add("href", root.Url); a.InnerText = root.Title; li.Controls.Add(a); if (root.ChildItems != null && root.ChildItems.Count > 0) { li.Attributes.Add("class", "submenu"); // li.Attributes.Add("style", "background-image: url('/Style Library/images/open.gif');"); if (root.ChildItems != null) { HtmlGenericControl ul = new HtmlGenericControl("ul"); foreach (var item in root.ChildItems) { //ul.Attributes.Add("rel", "closed"); //ul.Attributes.Add("style", "display:block"); li.Controls.Add(ul); int childLevel = level + 1; AddChildControl(ul, item, childLevel, item == root.ChildItems[root.ChildItems.Count - 1]); } } } }
private SiteMapItem GetFolderStructure(DirectoryInfo dir, string rootPath, int level) { var list = new List <SiteMapItem>(); var siteMapItem = new SiteMapItem { Name = dir.Name.Replace("-", " "), Path = dir.FullName.Substring(rootPath.Length).Replace('\\', '/'), Level = level, Sort = GetSort(dir.Name, level) ?? 100, Directories = list, HasChildren = dir.GetDirectories().Any() }; foreach (var child in dir.GetDirectories().Where(x => x.Name != "images" && x.Name != ".git" && x.Name != ".github" && x.Name != "Old-Courier-versions")) { list.Add(GetFolderStructure(child, rootPath, level + 1)); } siteMapItem.Directories = list.OrderBy(x => x.Sort).ToList(); return(siteMapItem); }
private SiteMapItem GetFolderStructure(DirectoryInfo dir, string rootPath, int level) { var siteMapItem = new SiteMapItem { name = dir.Name.Replace("-", " "), path = dir.FullName.Substring(rootPath.Length).Replace('\\', '/'), level = level, sort = GetSort(dir.Name, level) ?? 100 }; if (dir.GetDirectories().Any() == false) return siteMapItem; var list = new List<SiteMapItem>(); foreach (var child in dir.GetDirectories().Where(x => x.Name != "images")) { list.Add(GetFolderStructure(child, rootPath, level + 1)); } siteMapItem.hasChildren = true; siteMapItem.directories = list.OrderBy(x => x.sort).ToList(); return siteMapItem; }
public ActionResult FooterMenu() { return(PartialView(SiteMapItem.GetCatalogRoot(null))); }
private SiteMapItem ReadSiteStructure(SPWeb web) { SiteMapItem node = new SiteMapItem() { Title = web.Title, Url = web.Url }; if (web.Webs != null && web.Webs.Count > 0) { node.ChildItems = new List<SiteMapItem>(); foreach (SPWeb subWeb in web.Webs) { node.ChildItems.Add(ReadSiteStructure(subWeb)); } } return node; }