How To List

March 24, 2012
  • 404 Error Page

    Boyan came up with a great tutorial on a 404 page, complete with video!
    • Answered By: Boyan Barnev
    • Reference Url: Link
  • Add more default sized for images

    Go to Administration -> Settings -> Advanced and from there

    ContentView -> Controls -> AlbumsBackend -> Views -> AlbumsBackendInsert -> Sections -> DefaultImgSizeSection -> Fields -> NewSize -> ChoicesConfig - and there are the choices you can edit, update and add new sizes.
    • Answered By: Pavel Benov
    • Reference Url: Link
  • Auto-Resize Custom Designer Window

    function resizeDesigner() {
     if (dialogBase != null){
     dialogBase.resizeToContent(); //Refresh
     }
    }
    • Answered By: Unknown
    • Reference Url: None
  • Avoid Version errors with Assembly Binding

    This is the code to bind the most commonly used assemblies

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Telerik.Sitefinity" publicKeyToken="b28c218413bdf563" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion=""/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Telerik.Sitefinity.Model" publicKeyToken="b28c218413bdf563" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion=""/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="Telerik.Web.UI" publicKeyToken="121fae78165ba3d4" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion=""/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

     

    Add this to your web.config, and you shouldn't need to wait anymore for control vendors in the marketplace to recompile against the latest release.

    So obviously missing here are the "newVersion" numbers.  Just browse over to your bin directory and inspect the properties of the above DLLs to get the version # to paste in.  So if you just updated to 4.2.0.0 then put that in as the newversion.

    • Answered By: Unknown
    • Reference Url: Link
  • Hook into dynamic content events

    • Answered By: Unknown
    • Reference Url: None
  • Change CDN URLS

    This will let you specify the URLs to obtain jQuery, MsAjax, etc

    http://www.sitefinity.com/ClientsFiles/261752_jquerycdn.png 

    • Answered By: Unknown
    • Reference Url: None
  • Change the Title of a custom designer

    In the top of your SimpleView class where you define the designer class, just append this

    [ControlDesigner(typeof(MyCustomDesignerClass)), PropertyEditorTitle("My Custom Title")]

     

    This will replace the default "Edit" at the top of the popup designer!

    • Answered By: Unknown
    • Reference Url: None
  • Change Widget Icons

    1. Add class name in the backend toolbox settings
    2. Edit your stylesheet and add in that new class
    3. Define the image using a css background image (preferably a single sprite instead of a single image for every custom widget)
    • Answered By: Steve
    • Reference Url: Link
  • Change Url Regex Validation

    When you type a title it auto-generates the content item url based on a regex value.  Here's how you can change it for images (docs\etc are similar)

    Administration->Settings->Advanced->Libraries->Controls->ImagesBackend->Views->ImagesBackendEdit->Sections->AdvancedSection->Fields->UrlName->Validation and scroll down to the Regular Expression field
    • Answered By: Pavel Benov
    • Reference Url: None
  • Delete a Forms Column from the database

    As you properly pointed out, each time a from is created, a corresponding table for this form is also created in the database. However, you cannot simply delete the column. Each control is also stored in the sf_meta_fields table as a dynamic property, so after you restart your application, Sitefinity will first check all dynamic properties, compare them to the columns in the form tables, and if a column is missing, will recreate it. This is why if you want to delete the column of the control from the database you should perform the following steps:

    1. Delete the widget from your form;
    2. Go to sf_meta_types, find the id of your form and with this id, find the corresponding dynamic property in the sf_meta_fields table. 
    3. Then delete the property and delete the column in the form table.
    • Answered By: Jen Peleva
    • Reference Url: None
  • Fix: Dangerous Request.Form value Error

    This is an asp.net issue, and should be fixed in 4.5, but basically if you try and submit content in sitefinity and the content looks "dangerous" (like submitting html), then you get this error:

    A potentially dangerous Request.Form value was detected from the client

    Simple fix though (open your web.config):
    <system.web>
        <httpRuntime maxRequestLength="102400" requestValidationMode="2.0" />
        ....

    <pages validateRequest="false">

    Note: if you're using Claims Auth, httpRuntime should look more like this:
    <httpRuntime maxRequestLength="102400" requestValidationType="Telerik.Sitefinity.Security.Claims.CustomRequestValidator, Telerik.Sitefinity" requestValidationMode="2.0" />
    • Answered By: Stanislav Velikov
    • Reference Url: None
  • Forms Input Validatation

    Great article on how to set validation on the form input elements
    • Answered By: Grisha Karanikolov
    • Reference Url: Link
  • Get the content of a newsletter

    Now since the campaigns can be created either by writing html, created from template or building them as a page it is not just getting the text. You have to call a class called RawMessageSource which parses the message content and gives you the output html:

    NewslettersManager manager = new NewslettersManager();
      
    var camp = manager.GetCampaigns().FirstOrDefault();
      
    var rawMessage = new RawMessageSource(camp.MessageBody, NewslettersManager.GetRootUrl());
    //get the campaign text
    string text = rawMessage.Source;
    • Answered By: Radoslav Georgiev
    • Reference Url: Link
  • Get Category of an Item

    Get the list of Taxa Guids

    (IList<Guid>)ci.GetValue("Category")

    Convert them

    string c = String.Empty;
     
    foreach (var i in this.Categories) {
        TaxonomyManager manager = new TaxonomyManager();
        Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon item = manager.GetItem(typeof(HierarchicalTaxon), i) as Telerik.Sitefinity.Taxonomies.Model.HierarchicalTaxon;
     
        c += item.Title + "<br/>";
    }
     
    return c;
    • Answered By: Unknown
    • Reference Url: None
  • Get Filter Applied to a Widget

    You need to get an instance of the control on your page. Then you can
    call MasterViewDefinition.FilterExpression. This will get the filter
    that is set as a property of the control. Another option is overriding
    InitializeControls method MasterView that your widget uses and there
    check whether the dynamic filter expression returns results.<br />
    The third option is getting the date query from the url evaluator<br /> <br /> <div class="reCodeBlock" style="border: 1px solid #7f9db9; overflow-y: auto;"> <div style="background-color: #ffffff;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">var query = </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.Manager.GetEvents();</code></span></div> <div style="background-color: #f8f8f8;"><span style="margin-left: 0px ! important;"><code style="color: #000000;">query = </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.EvaluateUrl(query, </code><code style="color: blue;">"Date"</code><code style="color: #000000;">, </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.Host.DateEvaluatorPropertyName, </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.Host.UrlEvaluationMode, </code><code style="color: #006699; font-weight: bold;">this</code><code style="color: #000000;">.Host.UrlKeyPrefix);</code></span></div> </div> <br />
    and use <br /> <br />
    DataProviderBase.SetExpressions to see if there will be items returned by your control.
    • Answered By: Ivan Dimitrov
    • Reference Url: Link
  • Get the URL of an Item

    var test = App.WorkWith().NewsItem().Get().Urls.Where(u => u.RedirectToDefault == false);

    • Answered By: Ivan Dimitrov
    • Reference Url: Link
  • Get a Control Reference

     You should do the following - iterate through the Controls collection of a PageData and then use page managers .LoadControl() for each control and verify the returned result

    var control = pageManager.LoadControl(ctrl);
    if (control is ContentBlock){
      //Party
    }
     
    • Answered By: Lubomir Velkov
    • Reference Url: Link
  • Hide items from the toolbox

    hide an image
    • Answered By: Boyan Barnev
    • Reference Url: Link
  • Get Last Modified Pages

    var lastTwoPages = App.WorkWith()
                          .Pages()
                          .Where(p => p.Page != null && p.Page.Status == ContentLifecycleStatus.Live)
                          .Get()
                          .OrderByDescending(pG => pG.Page.LastModified)
                           .ToList();
    • Answered By: Boyan Barnev
    • Reference Url: Link
  • jQuery in your Masterpage

     

    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>

     

    <sf:ResourceLinks id="resourcesLinks" runat="server">
            <sf:ResourceFile JavaScriptLibrary="JQuery" />
        </sf:ResourceLinks>

     

    This is the preferred way to do it as it'll load whatever the current embedded jQuery version is inside of sitefinity.

    • Answered By: Ivan Dimitrov
    • Reference Url: Link
  • List of Pages which a certain control type

    var pm = PageManager.GetManager();
                var pnWithObjectType = pm.GetPageNodes()
                    .Where(pn => pn.Page != null)
                    .Where(pd => pd.Page.Controls.Any(c => c.ObjectType.StartsWith(typeof(MyProject.Namespace.ControlType).FullName)));
    • Answered By: Svetoslav Petsov
    • Reference Url: Link
  • Loading Tweets with Javascript

    1. Create the markup the json will be loaded into

      <div id="twitter">
          <a href="http://twitter.com/stevemcniven" class="action">Follow Me!</a>
          <div id="latest">
              <div id="tweet">
                  <div id="twitter_update_list">
                  </div>
              </div>
              <div id="tweetBottom">
              </div>
          </div>
      </div>
    2. In the page editor drop in a new Javascriptembed widget and place the following code into it's editor

      $(document).ready(function () {
        $("body").append(
          '<sc'+'ript type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></sc'+'ript>' +
          '<sc'+'ript type="text/javascript" src="https://twitter.com/statuses/user_timeline/stevemcniven.json?callback=twitterCallback2&count=1"></sc'+'ript>'
        );
      });

      Make sure to replace "stevemcniven" with whatever your twitter name is, and also you can change the "count" to something other than "1" :)

      **IMPORTANT STEP**
      • Make sure the widget loads the script at the end of the page before the end body tag...it's one of the radio buttons.
      • ...and this should be obvious, but please make sure you're loading jQuery somewhere so this runs :)
    • Answered By: Barney
    • Reference Url: Link
  • Modify Control Filtering

    This post by Boyan shows you how to change filters on your controls so they don't conflict.
    • Answered By: Boyan Barnev via Ivan Dimitrov
    • Reference Url: Link
  • Prefix your form tables in the database

    By default sitefinity just willy-nilly creates new tables for forms named as some version of the form name itself.  However most people who look at sql would prefer to have them all grouped together in sqlms. 

    So here's how you can set a prefix:
    1. Administration->Settings->Advanced
    2. ContentView->Controls->Forms Backend->Views->FormsBackendInsert->Sections->MainSection->Fields->Name
    3. Edit the prefix text property
    • Answered By: Pavel Iliev
    • Reference Url: Link
  • Programmatic Login

    void LoginButton_Click(object sender, EventArgs e)
    {
        //instantiate the Sitefinity user manager
        //if you have multiple providers you have to pass the provider name as parameter in GetManager("ProviderName") in your case it will be the asp.net membership provider user
        UserManager userManager = UserManager.GetManager();
        if (userManager.ValidateUser("admin", "password"))
        {
            //if you need to get the user instance use the out parameter
            Telerik.Sitefinity.Security.Model.User userToAuthenticate = null;
            SecurityManager.AuthenticateUser(userManager.Provider.Name, "admin", "password", false, out userToAuthenticate);
        }
    }

    Users are logged out by calling SecurityManager.DeleteAuthCookies()

    void LogoutButton_Click(object sender, EventArgs e)
    {
        SecurityManager.DeleteAuthCookies();
    }
    • Answered By: Radoslav Georgiev
    • Reference Url: Link
  • Rename a Forms Database Table

    I've been a big supported of the idea that forms need to have a prefix, otherwise your schema will go all to hell since the default naming is "sf_form_title"...bleh.  So this will retroactivly allow you to fix those.

    -- the old name of the form
    declare @oldName nvarchar(30) = 'sf_my_form';
    -- the new name of the form
    declare @newName nvarchar(30) = 'sf_forms_frm_my_form';
      
    -- rename the table with form entries
    exec sp_rename @oldName, @newName;
      
    -- change the form name in the forms description
    update [sf_form_description]
    set [nme] = @newName
    where [nme] = @oldName;
      
    -- change the type name of the form in the meta types
    update [sf_meta_types]
    set [class_name] = @newName
    where [class_name] = @oldName;


    • Answered By: Ivan Pelovski
    • Reference Url: None
  • Remove the Edit Button on a widget

    This is something that should be in there with "Granular Permissions"...however in the meantime, MVP Tim has a quick jQuery workaround!

    $('.rdTitleBar:first-child:contains("MyWidget1")').each(function () {
        $(this).find('.rdCommands').find('.rdMoreCommand').attr('style', 'border: 0px !important').end().find('a[title="Edit"]').parent().hide();
    });

    Thanks Tim!
    • Answered By: Unknown
    • Reference Url: Link
  • Run with multiple Worker Processes and avoid errors

    By default if Sitefinity is running in a single server scenario we use data cache for OpenAccess to minimize the queries to the database as OpenAccess caches the results.

    However if your website is setup to run under multiple application pools the data cache must be disabled. Otherwise each application pool will use the OpenAccess data cache and there will be discrepancies between the cache on both pools, and you will receive exceptions such as this one.

    In this case you must disable the cache by going to Administration -> Settings -> Advanced -> Data and set EnableDataCaching to false.

    • Answered By: Radoslav Georgiev
    • Reference Url: None
  • Speed up Development Cache

    The basic concept is that you're setting IIS to compile the pages to a RAM Disk, very smart!

    • Answered By: Jochem Bokkers
    • Reference Url: Link
  • Store your Config in the DB

    Configuration files are a "mirror" of the database. Every time you open or modify your project it gets information from its configuration files. Right before that configuration files verify that same configurations are available in the database, and only when this condition is fulfilled, information is send to your project. In other words, when your config file is opened, it connects to the database, makes sure that configurations at both places are the identical and then sends information for a change (dummy change) to your project . That's why you get a "file has changed" massage when no actual change has been done. With the release of Sitefinity 4.0  you are able to move your configuration files to the database, as shown in this blog

    post. If this is done, there won't be any verification between your project and the database and you won't get warning messages.

    Link1

    • Answered By: Radoslav\Jen
    • Reference Url: Link
  • Style Design Mode

    Its as simple as knowing the css classes to target!

    .sfPageEditor{} /* Any mode */
    .sfPageEditor.zeLayoutMode{} /* Layout View */
    .sfPageEditor.zeContentMode{} /* Widget View */

     

    Full Article

    • Answered By: Sitefinity Steve
    • Reference Url: Link
  • Setting a good ToolsFile.xml on the RadEditor

    Go to Settings->Advanced->Appearance

    So this is the RadEditor configuration...

    Here's a good basic Editor config that wont let your editors screw with Fonts (for example)

    <root>
      <tools name="MainToolbar" dockable="true" enabled="true">
            <tool name="Bold" />
            <tool name="Italic" />
            <tool name="Underline" />
            <tool separator="true"/>
           
            <tool name="InsertUnorderedList" />
            <tool name="InsertOrderedList" />
            <tool separator="true"/>
           
            <tool name="JustifyLeft" />
            <tool name="JustifyCenter" />
            <tool name="JustifyRight" />
            <tool separator="true"/>
     
            <tool name="ImageManager" text="Insert an image"/>
            <tool name="DocumentManager" text="Insert a document"/>
            <tool name="FlashManager" />
            <tool name="MediaManager" />
            <tool name="LinkManager" shortcut="CTRL+K"/>
            <tool name="Unlink" shortcut="CTRL+SHIFT+K"/>
            <tool separator="true"/>
            <tool name="FormatBlock" />
            <tool name="FormatCodeBlock" /> 
      </tools>
    </root>

    Save this to ~/App_Data/ToolsFile.xml

    ** The FormatCodeBlock is for me ** :)  General non-programming sites will not need it

    Ok so now in the settings area, change the StandardEditorConfiguration, and MinimalEditorConfiguration to be ~/App_Data/ToolsFile.xml

    Save, and done!

    • Answered By: Unknown
    • Reference Url: None
  • Transform RSS XML to HTML

    1. Go to Administration>Settings - click on Advanced link
    2. Go to Publishing and select Transform RSS XML to HTML option (see attached file)
    3. Save Changes 
    Note: you may need to reset your Website Project
    • Answered By: Sonya
    • Reference Url: Link
  • Use Content Selectors in your Custom Controls

    This is a blog post by Josh Morales (SelArom), shows how you can use the built-in sitefinity page, image, etc selectors in your custom controls.

    Good read!

    • Answered By: Josh Morales
    • Reference Url: Link
  • Write Advanced Filtering Expressions

    Category
    Visible = true AND Status = Live AND Category.Contains("{15727b71-1cfa-453f-868b-812ba4405513}")
    Visible = true AND Status = Live AND Category.Contains("{15727b71-1cfa-453f-868b-812ba4405513}") AND Category.Contains("{240bafff-a3d4-48d1-a176-780a50310109}")
    Visible = true AND Status = Live AND (Category.Contains("{15727b71-1cfa-453f-868b-812ba4405513}") OR Category.Contains("{240bafff-a3d4-48d1-a176-780a50310109}"))

    Tags
    Visible = true AND Status = Live AND Tags.Contains("{5aa31f67-5d42-44a0-86a2-01402913106f}")
    Visible = true AND Status = Live AND (Tags.Contains("{5aa31f67-5d42-44a0-86a2-01402913106f}") OR Tags.Contains("{199df0d9-8dd0-4aa6-b056-f68b375d7026}") )

    Custom fields for filtering (for number custom field)
    Visible = true AND Status = Live AND TotalVotes > 0
    Visible = true AND Status = Live AND TotalLikes = 7

    News Title
    Visible = true AND Status = Live AND Title.Contains("Featured news 3")
    Visible = true AND Status = Live AND Title.Contains("news")

    News Content
    Visible = true AND Status = Live AND Content.Contains("ipsum")
    Visible = true AND Status = Live AND Content.Contains("long established fact")

     Author

    Visible = true AND Status = Live AND Author = "basem"
    Visible = true AND Status = Live AND Author != "basem"
    Visible = true AND Status = Live AND Author.Contains("basem")
    Visible = true AND Status = Live AND Author.Contains("basem")

    Dates
    Visible = true AND Status = Live AND PublicationDate <= DateTime.UtcNow // Shows all
    Visible = true AND Status = Live AND PublicationDate < DateTime.UtcNow // Shows all
    Visible = true AND Status = Live AND PublicationDate > DateTime.UtcNow // Shows none
    • Answered By: Atanas Valchev
    • Reference Url: None
  • Get Sitefinity Version Number

    SystemInfo info = new SystemInfo();
    return info.Version.ToString();
    • Answered By: Unknown
    • Reference Url: None


Image Description

Steve McNiven-Scott

Best\Only Blogger on this site. Therefore defacto blogger of the year Award Winner.