Sunday, May 1, 2016

Json Data format issue /Date() in MVC

I struggled bit with getting over to this Json date format issue. I got the lead with Hanselman . Scott tried his best to point to right direction but all he was intended towards web api 2. I was having a issue with mvc underlying

After working on this for an hour I started getting lot of solution via stackoverflow and many other blog post.

We can handle this date issue at client side but I personally want to handle everything at server side.

I liked Bipin Joshi Solution, which is kind of straight forward or straight cut solution.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Xml.Linq;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;

namespace JsonNetExtension
    public class JsonNetResult: JsonResult
        public new object Data { get; set; }

        public override void ExecuteResult(ControllerContext context)
            HttpResponseBase response = context.HttpContext.Response;
            response.ContentType = "application/json";
            if (ContentEncoding != null)
                response.ContentEncoding = ContentEncoding;
            if (Data != null)
                JsonTextWriter writer = new JsonTextWriter(response.Output) { Formatting = Newtonsoft.Json.Formatting.Indented };
                JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings());
                serializer.Serialize(writer, Data);

Friday, April 22, 2016

C# Cool Code: Convert Enum to List

namespace ConsoleApplication1
    class Program
         enum SomeEnum
        class KeyValues
            public string Key { get; set; }
            public string Value { get; set; }
        static void Main(string[] args)

            List enums = ((IEnumerable)Enum.GetValues(typeof(SomeEnum)))
                .Select(c => new KeyValues() { Key = ((int)c).ToString(), Value = c.ToString() }).ToList();

            //List Model = new List(){ "1", "2", "3" };
            foreach (var item in enums.Select((value, i) => new { i, value }))

                Console.WriteLine("Collection Object Values : " + item.value.Value);
                Console.WriteLine("Collection Index : "+ item.i);

C# Cool Code : Foreach with Index iterator values

namespace PlayWithCollection
    class Program
        static void Main(string[] args)
            List Model = new List() { "1", "2", "3" };
            foreach (var item in Model.Select((value, i) => new { i, value }))

                Console.WriteLine("Collection Object Values : " + item.value);
                Console.WriteLine("Collection Index : " + item.i);

Tuesday, March 29, 2016

Sitecore : All about MultiList and Search

I was doing bit of R&D around implementing, writing custom multilist with search while doing my bit of research I understand sitecore has not unified the multilist with search in a way so that it can be used widely to solve problem for content author. May be there is less documentation out there where developer ends up writing custom implementation which can very well handled using right query.
Below I tried to sum up by putting some of the cool links a kind of reference to begin with.
Simple problem solved
By Raul- Nice explanation
Query Bug

Customize Multilist with search
StartSearchLocation=query:..&Filter=_latestVersion:*|-_templatename:Saved Query

By Fish Tank

Add Selected Item at top in the multilist

Wednesday, March 2, 2016

Azure Webjobs with some known Facts.

Recently we successfully migrated worker role Queue jobs to Web jobs and below are the set of issues we encountered.

Special thanks to Kanivalan Raju who got this compiled.

When you deploy web jobs in azure cloud, you may come across the following errors.

Error 1
Error :Command cmd was aborted due to no output nor CPU activity for 121 seconds.


add key = "SCM_COMMAND_IDLE_TIMEOUT" value = "100000"

add key = "WEBJOBS_IDLE_TIMEOUT" value = "100000"

Error 2 : Certificate with website_load
Its important to load your certificates with this key appsetting.



Add key ‘Add WEBSITE_LOAD_CERTIFICATES’ with thumbprint values as below
X509Certificate2 certificate=null;
X509Store certificateStore =new X509Store(StoreName.My, Storelocation.CurrentUser);

Error 3: Long file name
While publishing the webjob from VS, below error occurred and publish failed

The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resolution :

As mentioned in error, make sure the path and file name of the web job not exceeds 250

Hope these resolution comes handy for folks working on similar problem statement.