App_Code.Controls.WidgetContainer.DoesThemeWidgetContainerExist C# (CSharp) Method

DoesThemeWidgetContainerExist() public static method

Returns whether the theme contains a widget container file.
public static DoesThemeWidgetContainerExist ( bool existenceCheck ) : bool
existenceCheck bool
return bool
        public static bool DoesThemeWidgetContainerExist(bool existenceCheck)
        {
            // This is for compatibility with older themes that do not have a WidgetContainer control.
            return File.Exists(GetThemeWidgetContainerFilePath(existenceCheck));
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"></see> event.
        /// </summary>
        /// <param name="e">
        /// The <see cref="T:System.EventArgs"></see> object that contains the event data.
        /// </param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var zone = this.XmlDocument.SelectNodes("//widget");

            if (zone == null)
            {
                return;
            }

            // This is for compatibility with older themes that do not have a WidgetContainer control.
            var widgetContainerExists      = WidgetContainer.DoesThemeWidgetContainerExist();
            var widgetContainerVirtualPath = WidgetContainer.GetThemeWidgetContainerVirtualPath();

            foreach (XmlNode widget in zone)
            {
                var fileName = string.Format("{0}widgets/{1}/widget.ascx", Utils.RelativeWebRoot, widget.InnerText);
                try
                {
                    var control = (WidgetBase)this.Page.LoadControl(fileName);
                    if (widget.Attributes != null)
                    {
                        control.WidgetId  = new Guid(widget.Attributes["id"].InnerText);
                        control.Title     = widget.Attributes["title"].InnerText;
                        control.ShowTitle = control.IsEditable
                                                ? bool.Parse(widget.Attributes["showTitle"].InnerText)
                                                : control.DisplayHeader;
                    }

                    control.ID   = control.WidgetId.ToString().Replace("-", string.Empty);
                    control.Zone = this.zoneName;

                    control.LoadWidget();

                    // This will return the WidgetContainer with the control in it.
                    var widgetContainer = WidgetContainer.GetWidgetContainer(control, widgetContainerExists, widgetContainerVirtualPath);
                    this.Controls.Add(widgetContainer);
                }
                catch (Exception ex)
                {
                    var lit = new Literal
                    {
                        Text = string.Format("<p style=\"color:red\">Widget {0} not found.<p>", widget.InnerText)
                    };
                    lit.Text += ex.Message;
                    if (widget.Attributes != null)
                    {
                        lit.Text +=
                            string.Format(
                                "<a class=\"delete\" href=\"#\" onclick=\"BlogEngine.widgetAdmin.removeWidget('{0}');return false\" title=\"{1} widget\">X</a>",
                                widget.Attributes["id"].InnerText,
                                labels.delete);
                    }

                    this.Controls.Add(lit);
                }
            }
        }
All Usage Examples Of App_Code.Controls.WidgetContainer::DoesThemeWidgetContainerExist