How to call a method at specific day in week in c#

In this pervious article, we have discussed How to call a method once time in a day in C#   but if want to pass a method in a specify day in week then we can use below code. Here we use dayof week
DayOfWeek:- Seven days are in each week. We determine if a certain date is a Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, or Sunday. The DayOfWeek property, and the DayOfWeek enum type, can be used for this purpose.
In C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class specificdayinweek : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        DayOfWeek today = DateTime.Today.DayOfWeek;
        if(today == DayOfWeek.Monday)

            Response.Write("today is Monday");

        if (today == DayOfWeek.Tuesday)

            Response.Write("Today is Tuesday");

        if (today == DayOfWeek.Wednesday)

            Response.Write("Today is Wednesday");

        if (today == DayOfWeek.Thursday)

            Response.Write("Today is Thursday");


as we can use all seven days where we can our code we can put .

How to call a method once time in a day in c#

Many times we need to call a method once time in a day. In this article we have mentioned the code for this.

Source Code:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class onedaymethod : System.Web.UI.Page
    static DateTime objdatetime;
    protected void Page_Load(object sender, EventArgs e)
        if (objdatetime == DateTime.Today)
            //this method call everythime in a day
            Response.Write("this message show everytime in a day");
        objdatetime = DateTime.Today;
        //this method call only one time in a day
        Response.Write("this message show only time in a day");


How to check leap year or not in sql server

Many times in the interviewer ask the question how to check which year is leap years or not in SQL Server

Below this method we can check the which year this leap years or not

DECLARE @year int

SET @year = 2016

 (@year % 4 = 0) and (@year % 100 != 0) or

        (@year % 400 = 0)
then 'YES' else 'NO'
AS [Is Leap year?]
Note :-
If we want to check current then we need to put :-
SET @year =  YEAR(getdate())


Delete duplicate rows from a table in sql server

Much time we need to remove data according to some columns. In this article we will delete the duplicate data according email . Lets’ see:-

Database table:-

Sql Query:-
with TempTable as


select *, row_number() over (partition by Email order by Email) as Rank

from reg


Delete from TempTable where Rank >1


MVC interview Question and Answer Part-1

Question: - What is MVC?
Answer:- MVC is a software architecture pattern for developing web application. It is handled by three objects Model-View-Controller.
Applications business logic is contained within the model and is responsible for maintaining data.
View: - It represents the user interface, with which the end user communicates. In short all the user interface logic is contained within the VIEW
Controller:-It is the controller that answers to user actions. Based on the user actions, the respective controller responds within the model and chooses a view to render that display the user interface.  The user input logic is contained with-in the controller

Question: - why MVC?
*.MVC segregates your project into a different segment, and it becomes easy for developers to work on
*.It is easy to edit or change some part of your project that makes project *.less development and maintenance cost
MVC makes your project more systematic

Question: - Is it must to decorate action methods with public access modifier?
Answer: - Yes, every public method will become action methods automatically.

Question: - What about non-public methods?
Answer: - They are simply methods of a class and not available publicly. In simple words these methods cannot be invoked from the web.

Question: - What is the relation between ActionResult and ViewResult?
Answer: - ActionResult is the abstract class whereas ViewResult is the multi-level child of ActionResult. Multilevel because, ViewResult is the child of ViewResultBase and ViewResultBase is the child of ActionResult.

Question: - What is ContentResult?
Answer: - ViewResult represents a complete HTML response whereas ContentResult represents a scalar text response. It’s just like returning pure string. Difference is ContentResult is an ActionResult wrapper around string result. ContentResult is also the child of ActionResult.

Question: - Is it possible to invoke View function without Parameter?
Answer: - Yes, then it will find the view with name “CurrentActionName”.

Question: -what is ViewData?
Answer:-ViewData is a dictionary, which will contain data to be passed between controller and views. Controller will add items to this dictionary and view reads from it.

Question: - Why casting is required?
Answer:-ViewData holds objects internally. Every time a new value is added into it, it gets boxed to object type.
So unboxing is required every time we try to extract value out of it.

Question: - what is ViewBag?

Answer:-ViewBag is just a syntactic sugar for ViewData. ViewBag uses the dynamic feature of C# 4.0 and makes ViewData dynamic.
ViewBag internally uses ViewData

Question:- Disadvantages of ViewData and ViewBag?
Answer:-ViewData and ViewBag is a good option for passing values between Controller and View. But in real time projects it’s not a good practice to use any of them.
Let’s see some disadvantages
No Type safety and no compile time errors
If we try to cast values to wrong type or if we use wrong keys while retrieving the values, we will get runtime error.
No Proper connection between Data sent and Data Received
In MVC, controller and View are loosely connected to each other. Controller is completely unaware about what’s happening in View and View is unaware about what’s happening in Controller.
Performance issues
Values inside the ViewData are of type Object. We have to cast the value to correct type before using it. It adds additional overhead on performance.

Question: - what is ViewModel?
Answer: - ViewModel is one of the unspoken layer in the Asp.Net MVC application. It fits between Model and View and act as data container for View.

Question: - Difference between Model and ViewModel?
Answer: - Model is Business specific data. It will be created based on Business and Database structure. ViewModel is View specific data. It will be created based on the View.

Question: - How Model and ViewModel will be connected?

Answer: - Model and ViewModel should be independent of each other. Controller will create and initialises ViewModel object based on one or more Model object.

ASP.NET MVC Version History

HTML5 Geolocation to show current location with Google Maps API

Geolocation allows you to give your current location information to the browser. Google use Geolocation a lot, especially for things like Google Maps, you’re bound to have seen the popups ‘This page would like to use your current location’. If so, you’ve experienced HTML5 Geolocation.

Sourec Code :-
<!doctype html>
    <meta charset="utf-8">
    <title>HTML5 Geolocation to show current location with Google Maps API</title>
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
        #google_canvas {
            height: 100%;

            #google_canvas h1 {
                font-size: 16px;

            #google_canvas h2 {
                font-size: 14px;
                font-weight: 300;

    <div id="google_canvas"></div>

    <script src="//"></script>

        (function () {

            if (!!navigator.geolocation) {

                var map;

                var mapOptions = {
                    zoom: 15,
                    mapTypeId: google.maps.MapTypeId.ROADMAP

                map = new google.maps.Map(document.getElementById('google_canvas'), mapOptions);

                navigator.geolocation.getCurrentPosition(function (position) {

                    var geolocate = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

                    var infowindow = new google.maps.InfoWindow({
                        map: map,
                        position: geolocate,
                                                         '<h1>Location pinned from HTML5 Geolocation!</h1>' +
                                                         '<h2>Latitude: ' + position.coords.latitude + '</h2>' +
                                                         '<h2>Longitude: ' + position.coords.longitude + '</h2>'



            } else {
                document.getElementById('google_canvas').innerHTML = 'No Geolocation Support.';





Note :On page load browser asks you for access your location so once you need to allow it.

Hey, we've just launched a new website. You'll like it -
Join Our Newsletter