Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Thursday, 3 March 2022

Redirecting Custom error in .Net Core

When we where working on .net mvc or aspx we  where configuring into the web.config file as default error page, like below.

 

<system.web>

    <customErrors mode="On">

      <error statusCode="404" redirect="/PageNotFound?" />

      <error statusCode="302" redirect="/unauthorised" />

    </customErrors>

</system.web>

 

But in .Net core we dont have web.config file to configure default error page.

In this case we need to configure it in startup.cs file.

 

Monday, 4 March 2019

selenium basics for beginners


 Selenium Introduction

 l  Selenium is an open source tool (no cost involved – free to download from Seleniumhq) “https://docs.seleniumhq.org/download/”
l  Selenium supports language like HTML, Java, PHP, purl, Python, Ruby and C# .
l  Selenium supports multiple web browsers like, IE, Firefox, Chrome, Opera
l  Selenium supports multiple Operating systems like Windows, Linux, Mac
l  Selenium Components


Saturday, 9 February 2019

Call python code in C# using IronPython


Why it’s required?

Python has lots of  useful library that we can utilise in our application and get that functionality in our webapplication. So just trying how to get the python features in MVC applications.

Using the Ironpython  to call the python code in C# code.  Follow the steps and use the below code to call the python code.

1.       Taking the reference of IronPython  using the Nuget Package as like below.


Monday, 14 January 2019

C# Interview Questions

It is C# basic interview question for beginners level.


1.       What is Class?
Ans: Collection of objects is called class. It is a logical entity.
A class can also be defined as a blueprint from which you can create an individual object. Class doesn't consume any space.

2.       Difference between Class and Objects?
Ans: Any entity that has state and behavior is known as an object. An Object can be defined as an instance of a class. An object contains an address and takes up some space in memory.

3.       What is Oops concept?
a.       What is inheritance?
Ans: When one object acquires all the properties and behaviors of a parent object, it is known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.

b.       What is Encapsulation?
Ans: Binding (or wrapping) code and data together into a single unit are known as encapsulation.

c.       What is Polymorphism?
Ans: If one task is performed by different ways, it is known as polymorphism.

d.       What is Abstract?
Ans: Hiding internal details and showing functionality is known as abstraction

Saturday, 26 May 2018

XMLformatting in c#



Format the minify XML into readable way which help to view it properly and easy to read in C#. You can make your simple xml formatter by using the below few lines of code in C#.
static void Main(string[] args)
        {
            try
            {
                string xml = @"<?xml version='1.0' encoding='UTF - 8' ?><employees><employee><id>1</id><firstName>Leonardo</firstName>
            <lastName>DiCaprio</lastName><photo>https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr5EO4zbh_Vl_1W3Pxwo9ty6C7GZuDhME8KIVAXi0-PmFL-jRxzLS_mHhWjSwZARP2Uzq-ci7TvJR_3YO056bYOf1PBV7zS2TeNv8gYyt54xH8toD7vZu0kMKSVIijC4QEZy5rB0I8ujA/s200/Leonardo+Dicaprio7.jpg</photo>
            </employee><employee><id>2</id><firstName>Johnny</firstName><lastName>Depp</lastName>
            <photo>http://4.bp.blogspot.com/_xR71w9-qx9E/SrAz--pu0MI/AAAAAAAAC38/2ZP28rVEFKc/s200/johnny-depp-pirates.jpg</photo>
            </employee><employee><id>3</id><firstName>Hritik</firstName><lastName>Roshan</lastName><photo>http://thewallmachine.com/files/1411921557.jpg</photo>
            </employee></employees> ";

Friday, 8 December 2017

The specified type member '' is not supported in LINQ to Entities.

Getting issue with entity framework for newly added column into database table.

The specified type member '' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.



Tuesday, 14 November 2017

Convert Object to DataTable in C#


Converting object to datatable using the C# code, it help in many places like doing the bulk insertion of data to database. There we need to send data in the form of table.
Suppose we have an Employee Class.

public class Employee
    {
        public int EmployeeId { get; set; }
        public string EName { get; set; }
        public int Age { get; set; }
        public decimal Salary { get; set; }
    }

Now instead of creating method for converting the object to datable, we will create a generic extension method which will convert any type of object into datatable.
public static class Utility

Sunday, 6 August 2017

@html.grid mvc 5


Step by step process to bind MVC.Grid in MVc application
Grid will be display like below

Thursday, 3 August 2017

Generate Property and Methods Tool

You can automatically generate the property and method and insert query which help you to build the backed code faster.


Create an window application like below ;


Sunday, 30 July 2017

logging using nLog

nlog is free logging platform which use in .net, mobile platform. Its very easy to use and integrated with Visual studio Nuget package manager.

1.       Creating console application to check how to use nLog.


2.       Now add the nlog from Nuget package.

Tuesday, 20 June 2017

Program to print pattern in C#

1. Program to print Half Pyramid using *

static void Main(string[] args)
        {
            /// Printing of star pyramid
            PrintHalfPyramid(9);


         }

Monday, 12 June 2017

Data structure tutorial for beginners

1.     What is Data structure?

How effectively we are storing the data it’s called as data structure.

Data structure is particular way of storing and organizing data so that it can use efficiently.
Structuring the data which really help us to manage it properly.

Let’s take the example of Dictionary (defined into liner form), Cash book (defined in tabular form)

It is not a language it’s a set of algorithm or process which help to store data effectively.


Data structure à Algorithm à Abstract Data type à Set of rules
Algorithm à Array, Stack, Queue, linked list, tree, graphs

Algorithm (data structure) is divided into two types ::

Thursday, 7 July 2016

Console application pass parameters

Target of application to be like calculator, you will pass the string like n1+n2-n3/n4*n5 and it will calculate the value and give the result. e.g. 2+2-2*2/2 will give the result as 2

Sunday, 5 June 2016

Difference between string and String builder

Show below for demonstration of  Difference between string and String builder.

String
String belongs to system namespace. Its commonly use reference type.  If we are not perform any operation string is fast.  We can initialize the string directly like below.

string str = "name";

Friday, 20 May 2016

Visual studio shortcut keys.

Find out the Visual studio shortcut keys which helps in day to day development activity and makes your development fast. These visual studio shortcut keys and just common keys to use.


SNO
Short Cut Key
Description
1
Ctrl+C , Ctrl+Ins
Copy Content
2
Ctrl+X, Shift+Del
Cut content
3
Ctrl+V, Shift+Ins
Paste content
4
Ctrl+Shift+V, Ctrl+Shift+Ins
Cycle Clipboard Ring, paste the multiple copy content
5
Del, Ctrl+Del
Delete

Tuesday, 12 April 2016

encode and decode query string asp.net

Use below code to encode the query string using AntiXSS library for it you need to refer the antixss library in your code.

What is Antixsslibrary ?
It helps you to protect your code from cross site scripting. It helps to encode the text.
Cross site scripting (XSS) occurs  mostly on  due following .
1. When Dynamically data changing.
2. Passing the data through query string.
3. Displaying data to UI which is allowing to insert from user (they can insert the script aswell)
4. Showing any messages to UI.

clear controls in asp.net

Suppose you have the list of input control that you want to clear it after saving the records or updating the records, you can use the generic method and that you can call from your derived class and pass the control.

Use below method  for same it will clear your input control from C# code behind.

Wednesday, 17 February 2016

Dependency Injection in MVC using Unity


What is dependency Injection?

Dependency Injection makes your application as decoupled and loosely couple to your code. It use to resolving the dependency of your code. It follow the Dependency Inversion principle of SOLID.
This is the way of injecting the code based on the feature required in application.
There are basically three ways you can approach to implement the dependency Injection.

1.       Using Property Getter and setter
2.       Using Constructor.
3.       Through Interface.


How Implement the Dependency Injection in MVC using Unity?

Wednesday, 10 February 2016

Difference between Delegate, Func, Action and Predicate.

Lets first see what is delegate.

If you will say delegate always one thing is come into our mind, a function pointer calling as an argument.
But it’s no sense with this Definition its showing the concept of use of delegate it won’t say why we need it and when we need this delegate.
For this we need to check with the English meaning of delegate, a representative. e.g Indian delegate go to US to deal something.
So this representative will give the time to time details of the operation and this delegate is the wrapper for our India which we hide but to present to the US also.

Sunday, 31 January 2016

How to call Stored Procedure in Entity Framework

 Entity  frame work providing the option of adding, updating or deleting the records. It is also giving the way of calling the store procedure in entity Framework to Insert, Update and Delete the options.
Entity framework will create User defined function for store procedures.
 Let’s see how we can add call the store procedure in entity frame work.
1.              Creation of store procedure in database.