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. 

Sitecore Rich text editor - stripping Iframe and Web contols.

Turn off HtmlEditor.SupportWebControls setting in web.config:


<setting name="HtmlEditor.SupportWebControls" value="false"/>

Monday 28 January 2013

storing values in cache memory(Not sessions not applications)


public static class CacheUtils
    {
        private static readonly Cache cache = HttpRuntime.Cache;
        
        /// <summary>
        /// Gets data from cache      
        public static Object GetFromCache(string key)
        {
            return cache[key];
        }      
 
        public static void InsertIntoCache(string key, int cacheTimeInMinutes, Object obj)
        {
            cache.Insert(key, obj, nullDateTime.Now.AddMinutes(cacheTimeInMinutes),
                          Cache.NoSlidingExpiration, CacheItemPriority.Normal, OnRemove);
        }
 
        public static void OnRemove(string key, object cacheItem, CacheItemRemovedReason reason)
        {
            //log.Info("Object removed from cache: Key-" + key + ": Reason-" + reason);
        }
 
        public static void RemoveFromCache(string key)
        {
            cache.Remove(key);
        }
 
    }

Sunday 27 January 2013

Reverse a string and sentence Linq Query


A string Reverse
string yString = "String to reverse";                
string rString = yString.Reverse().ToString(); 
Sentence reverse with each word in it...
string rString = string.Join(" ",from s in yString.Split(' ')
                                  select new String(s.Reverse().ToArray()));

Monday 14 January 2013

Reg Expressions validator imp list


 Email : "^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"



Only Numbers With Decimal :  "^[0-9]*\.?[0-9]+$"

Alphanumeric only :   "^[a-zA-Z0-9]*$"

Numbers with length between 2 to 5 Ex : "^([0-9]{2,5})$"

Numbers with Exact lenght(Example 5) : "^(\d{5})$"