Skip to content

Instantly share code, notes, and snippets.

View SitefinityGuru's full-sized avatar

Sitefinity Guru SitefinityGuru

View GitHub Profile
@SitefinityGuru
SitefinityGuru / SitefinityModuleCheck.cs
Created March 5, 2013 04:32
Demonstrates how to check if Sitefinity modules are installed and activated or disabled.
BlogsManager blogMgr = null;
NewsManager newsMgr = null;
EventsManager evMgr = null;
// retrieve the System Configuration
var systemConfig = Config.Get<SystemConfig>();
// blogs
var blogModuleConfig = systemConfig.ApplicationModules[BlogsModule.ModuleName];
if (blogModuleConfig.StartupType != StartupType.Disabled)
@SitefinityGuru
SitefinityGuru / SitefinityFluentApiWithProvider.cs
Created November 28, 2012 04:04
Using the Sitefinity Fluent API With a Different Provider
var providerName = "MyCustomProviderName";
using (var api = App.Prepare().SetContentProvider(providerName).WorkWith())
{
// do stuff with api
}
@SitefinityGuru
SitefinityGuru / AddToCartWidget.ascx
Created October 5, 2012 15:34
Ecommerce Products Minimum and Maximum Quantity
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddToCartWidget.ascx.cs" Inherits="SitefinityWebApp.Templates.AddToCartWidget" %>
<%@ Register TagPrefix="sf" Namespace="Telerik.Sitefinity.Web.UI" Assembly="Telerik.Sitefinity" %>
<asp:UpdatePanel ID="UpdatePanel" runat="server">
<ContentTemplate>
<sf:Message runat="server" ID="addedToCartMessage" CssClass="sfMessage sfTopMsg"
RemoveAfter="10000" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Label ID="quantityLabel" runat="server" Text='<%$Resources:OrdersResources, QuantityColon %>'
AssociatedControlID="quantity" CssClass="sfTxtLbl" />
@SitefinityGuru
SitefinityGuru / HideableContentBlock.cs
Created July 27, 2012 18:26
Hideable Sitefinity Content Block Widget
public class HideableContentBlock : ContentBlock
{
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
// always render in page editor
if (this.IsDesignMode() || this.IsPreviewMode())
{
base.Render(writer);
return;
}
@SitefinityGuru
SitefinityGuru / IncludeScripts.ascx
Created July 27, 2012 14:53
Include jQuery and other built-in libraries in Sitefinity
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
<sf:ResourceLinks ID="resourcesLinks" runat="server">
<sf:ResourceFile JavaScriptLibrary="JQuery" />
<sf:ResourceFile JavaScriptLibrary="MooTools" />
<sf:ResourceFile JavaScriptLibrary="Prototype" />
<sf:ResourceFile Name="~/Widgets/myJavascript.js" />
</sf:ResourceLinks>
@SitefinityGuru
SitefinityGuru / DynamicContentSelectorField.cs
Created July 19, 2012 21:44
Sitefinity Dynamic Content Selector Field
/// <summary>
/// A simple field for displaying related dynamic content items in a drop-down menu.
/// Requirements:
/// * the name of the field must exactly match the name of the content type being displayed
/// * the content type must be within the same module as the content type using this field
/// </summary>
public class DynamicContentSelectorField : ChoiceField
{
/// <summary>
/// Defaults the rendering of the list as a drop-down menu
@SitefinityGuru
SitefinityGuru / GetPageNodeUrl
Created June 22, 2012 22:50
Get Page Node Url From Guid
public string GetPageUrl(Guid PageID)
{
var mgr = PageManager.GetManager();
var pageNode = mgr.GetPageNode(PageID);
return pageNode.GetFullUrl();
}
@SitefinityGuru
SitefinityGuru / PublishContentItem.cs
Created June 14, 2012 16:36
Publishing Dynamic Sitefinity Module Items
var bag = new Dictionary<string, string>();
bag.Add("ContentType", FULL_NAME_OF_CONTENT_TYPE);
WorkflowManager.MessageWorkflow(dynamicContentItem.Id, dynamicContentType, null, "Publish", false, bag);
@SitefinityGuru
SitefinityGuru / AddControlDefaultPermissions.cs
Created June 8, 2012 15:25
Add a Control to a Sitefinity Page with Default Permissions
var ctrl = pageManager.CreateControl<PageControl>("~/Path/To/Control.ascx", "ContentPlaceholderName");
pageManager.SetControlDefaultPermissions(control);
pageData.Controls.Add(control);
@SitefinityGuru
SitefinityGuru / IncludeCss.ascx
Created June 7, 2012 22:21
Including CSS in a Sitefinity User Control
<%@ Register TagPrefix="sitefinity" Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" %>
<sitefinity:ResourceLinks ID="ResourceLinks1" runat="server" UseEmbeddedThemes="false">
<sitefinity:ResourceFile Name="~/Path/To/File.css" />
</sitefinity:ResourceLinks>