Wednesday 6 November 2013

Sitecore - sublayout GetParametervalue

private string GetParameterValue(string key)
        {
            Sublayout sublayout = uc != null ? (uc.Parent as Sublayout) : (this.Parent as Sublayout);
            if(sublayout != null)
            {
                if(!String.IsNullOrEmpty(sublayout.Parameters))
                {
                    Database db = Sitecore.Context.Database;

                    NameValueCollection parameters = Sitecore.Web.WebUtil.ParseUrlParameters(sublayout.Parameters);

                    if(parameters != null && parameters[key] != null)
                    {
                        return parameters[key].ToString();
                    }
                }
            }

            return String.Empty;

        }

Sitecore DMS Poll Module

·         After Installation od Sitecore DMS, we can able to install DMS Poll Module on it.
·         Software can be downloaded from here - http://marketplace.sitecore.net/en/Modules/Poll_Module.aspx
·         The document is for old OMS Poll Installation but it will be understandable for the new DMS as well apart from two points metioned below:
o    DMS Poll Voting Sublayout​ - Editor options (which are wrong by default. Change it to below paths)
§  Datasource Location - /sitecore/content/Home/LeagueAgainstCruelSports/Site Collection/Polls​
§  DataSource Template - /sitecore/templates/Sitecore Modules/DMS Poll module/DMS Poll

o    While adding poll control to the page presentation details add the created poll in the Datasource not as a parameter.

Sitecore RSS Feed Custom Functionality

Sometimes it is difficult to write complex xPath and sitecore Queries, to make RSS Feed work like our requirements. So, it is better to Override the Sitecore class called Sitecore.Syndication.PublicFeed.
 
Example
 
public class CustomFeed : Sitecore.Syndication.PublicFeed
    {
        public List<Item> EmbargoPressReleases = new List<Item>();

        public override IEnumerable<Sitecore.Data.Items.Item> GetSourceItems()
        {
            var Items = base.GetSourceItems();

            foreach(Item i in Items)
            {
                if(i.TemplateID == Consts.Template.PressRelease)
                {
                    if(Sitecore.DateUtil.IsoDateToDateTime(i.Fields[Consts.FieldName.PublishDate].ToString()) <= DateTime.Now)
                    {
                        EmbargoPressReleases.Add(i);
                    }
                }
            }
            return EmbargoPressReleases;
        }

    }

Sitecore FastQuery Returing Items in wrong Order.

Remove Fast from your query. Or sort it with the field name __sortOrder

Sitecore SubItems Sort Order.

Use the Home Ribbion Sorting Tab.

Object of type 'System.Int32' cannot be converted to type Object of type 'System.Int32' cannot be converted to type 'System.Web.Security.Cryptography.Purpose

<!--  REMEMBER LAST LOGGED IN USER NAME 
            Specifies whether Sitecore will remember the last logged in user name on the login page (stored encrypted in a cookie). 
            If you set this to false, the user name field on the login page and change password page will always be blank.
            Default: true
      -->
 <setting name="Login.RememberLastLoggedInUserName" value="false"/>


Sitecore and .net 4.5 Bug Fixed

Maximum request length exceeded – No File Upload

If you are not using view state do – Enableviewstate = “false”.

If you need to store view state. Check why the data is so huge on view state. My case had a spam email with so much of data in it.