Nov 9, 2016

Handling dynamically created RadioButtons in ASP.NET MVC




    @model ExampleViewModel
    @using (Html.BeginForm())
        <table class="table table-bordered table-striped">
            @for(int i=0;i<Model.Questions.Count;i++)
                var question = Model.Questions[i];
                        @foreach (var answer in question.Value)
                            <input type="text" name="Model.Answers[@question.Key].Key" value="@question.Key" />
                            <input type="hidden" name="Model.Answers.Index" value="@question.Key" />
                            @Html.RadioButton("Model.Answers[" + question.Key+"].Value", answer, false) @answer
                    <input type="submit" class="btn btn-primary" value="Submit" />

In model.Questions text and values for the radio button can be added through controller. When the form is submitted ASP.NET MVC Model model.Answers will hold the dictionary containing the submitted values,

Aug 5, 2016

Marathi Keyboard v4.0 released on github

Virtual Keyboard Software to type in Devnagri script
Wrote C# code to map each key on keyboard with devanagari unicode font.

Source available on github:

  1. Type in marathi in any windows application easily using virtual keyboard software
  2. To switch between Marathi & Hindi language typing mode press "Ctrl+M"
 Key Mappings:
अ : A आ : a इ : i ई: I उ: u ऊ: U
ए: e ऐ: E ओ: o औ: O अं: N अ: : :
क : k ख : K ग : g घ : G ङ
च : c छ : C ज : j झ : jH ञ : Y
ट : T ठ : TH ड : D ढ : DH ण : nH
त : t थ : tH द : d ध : dH न : n
प : p फ : pH ब : b भ : bH म : m
य : y र : r ल : l व : v
श : sH ष : S स : s
ह : h ळ : L क्ष : x ज्ञ : Z
श्र: W ॐ : Q कृ: @
काना: a पहिली वेलांटी: i दुसरी वेलांटी: I पहिला उकार: u दुसरा उकार: U एक मात्रा: e दोन मात्रे: E

Download setup file:

Mar 16, 2015

C# Parse JSON into dynamic object

Parse JSON into dynamic object using Newtonsoft JSON library:
JsonReader jsonReader = new JsonTextReader(new StringReader(strText)) { DateParseHandling = DateParseHandling.None };
dynamic jsonObj = JObject.Load(jsonReader);

Mar 6, 2015

Electric Appliance Automation - An IoT Project using Windows Azure

I have started working on application Internet of things home automation using Windows Azure

In this article we’ll have look at controlling home appliances remotely over HTTP using a small API toolset we’ll create using ASP.NET web api. On top of that we’ll push the current device status to the client in real time with SignalR(windows service hosted)

We will Control following home appliances through windows service:
1. FAN - on/off, Speed adjust
2. Lights - on/off
3. Air Conditioner - on/off, Temperature Control
4. Speakers – on/off, Play/Pause/Stop song

Feb 20, 2015

Oct 17, 2014

How to implment CRON job in windows service using C#

In this post we will go throught the steps involved in creating a windows service which will repeat according to specified CRON EXPRESSION

1. Create a windows Service named "CronService"

2. Right click on the project in solution explorer, click on "Manage NuGet Packages"


3. Search for "Quartz.NET" and click on "Install" to install the package


4. Create a interface called "ITaskScheduler"

public interface ITaskScheduler
 string Name { get; }
 void Run();
 void Stop();
5. Create a class "TestTask" which inherits from "IJob" (IJob is an interface provided by, you need to import the "Quartz" namespace in this class)

public class TestTask : IJob
 public void Execute(IJobExecutionContext context)
  //Your main code goes here

6. Right click on the project in solution explorer, click on "Add Reference", select "System.Configuration" from .NET tab 

7. Add "TaskScheduler" class which will implement the above created interface "ITaskScheduler"


8. Add key in AppSettings section of app.config which will hold the Cron Expression

The current cron expression "0 0/15 * 1/1 * ? *" means that the service will run every 15 minutes.
Format of the cron expression is: [Minutes] [Hours] [Day of month] [Month] [Day of week] [Year]
You can get more information about cron expression from following page:
Cron Expression

You can obtain cron expression for your own schedule from following website:

Finally in your service's main class you need to write following code:

Please note that you need to write your code in the "TestTask" class's 'Execute' method and not in 'OnStart' method of your windows service.

How to find common words between two SQL variables

MSSQL How to find common words between two sentences:
CREATE FUNCTION [dbo].[EscapeXml](@data NVARCHAR(MAX))
 --< (<), & (&), > (>), " ("), and ' (')
 SELECT @t = REPLACE(REPLACE(REPLACE(REPLACE(@data,'<','<'),'&','&'),'"','"'),'''',''')
CREATE FUNCTION [dbo].[fnSplit](@data NVARCHAR(MAX), @delimiter NVARCHAR(5))
RETURNS @t TABLE (rowNum int IDENTITY(1,1), data NVARCHAR(max), descriptor varchar(255) NULL)
    SELECT @data = [dbo].[EscapeXml](@data)
    SELECT    @textXML = CAST('' + REPLACE(@data, @delimiter, '') + '' AS XML);

    INSERT INTO @t(data)
    SELECT  RTRIM(LTRIM(T.split.value('.', 'nvarchar(max)'))) AS data
    FROM    @textXML.nodes('/d') T(split)

SELECT as common
FROM dbo.fnSplit('This is sentence1 test',' ') sentence1 
INNER JOIN dbo.fnSplit('This is sentence2 test',' ') sentence2 ON =