All posts by Thiyagu

How to Delete a Folder or File using PowerShell

Use PowerShell to Delete a Single File or Folder

Before start executing the Delete powershell command we need to make sure you are logged in to the server or PC with an account that has full access to the objects you want to delete.

# Using PowerShell commnads to delete a file
Remove-Item -Path "C:\dotnet-helpers\DummyfiletoDelete.txt"

The above command will excute and delete the “DummyfiletoDelete.txt” file which present inside the “C:\dotnet-helpers” location.

Use PowerShell to Delete all File and Folders inside the folder

We can also use wildcard ‘*’ characters to remove multiple items. For example, this command removes all the files in “C:\dotnet-helpers\*.*”

# Using PowerShell commnads to delete all file
Remove-Item -Path "C:\dotnet-helpers\*.*"

# Using PowerShell commnads to delete all file and folders
Remove-Item -Path "C:\dotnet-helpers\*.*" -recurse

Recurse drills down and finds lots more files. The –recurse parameter will allow PowerShell to remove any child items without asking for permission. Additionally, the –force parameter can be added to delete hidden or read-only files.

Using -Force command to delete files force fully

# Using PowerShell commnads to delete all file force fully
Remove-Item -Path "C:\dotnet-helpers\*.*" -Force

The above command will delete all hidden or read-only files from the location “C:\dotnet-helpers\”

ASP.NET Core: My First New Project

In this tutorial section, we will discuss how to create a new project in Visual Studio using ASP.NET CORE. Once you have installed the Visual Studio 2015 tooling, you can start building a new ASP.NET Core Application .

STEP: 1

Once you have installed the Visual Studio 2015 tooling, you can start building a new ASP.NET Core Application using File → New Project menu option.

STEP: 2

On the New Project dialog box, you can able to see the three different templates for Web projects as shown below. After selecting ASP.NET Core Web Application (.NET Core),specify the location and name for your ASP.NET Core project click OK

ASP.NET Web Application − The simple ASP.NET application templates .

ASP.NET Core Web Application (.NET Core) − This will start you with a crossplatform compatible project that runs on the .NET Core framework.

ASP.NET Core Web Application (.NET Framework) − This starts a new project that runs on the standard .NET Framework on Windows.

STEP: 3

In the below dialog box, you can select a specific template for the ASP.NET application from the available ASP.NET Core Templates. Here, we select and start with an empty template. This would help us build it from scratch. Let us select the Empty template, turn off the Host in the cloud and click OK.

Now the Visual Studio will launch your new project. In the Solution Explorer window, you will see all the files that are in this project.

STEP: 4

Now you can run your application by pressing Ctrl+F5 or by going to the Debug menu. After going to the Debug menu, select Start Without Debugging.

STEP: 5

We can see it display only Hello World! This runs on http://localhost:44432. In your window system tray, you can also see that IIS Express is running as shown below.

What do you think?

I hope you have idea about creating first ASP.NET CORE application. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

ASP.NET Core – Project Structure

If we had created a new blank project (EMPTY template) of ASP.NET Core in VS 2015, we see the following structure at the start. Here you can see a couple of things like wwwroot, Dependencies, Startup class and project.json and also you  see some other things like “References” and “Properties” these are the common parts of the .NET application.

 

 global.json

The file allows selection of the .NET Core tools version being used through the sdk property. The version (and optionally run time and architecture) are important because your computer have multiple versions of dnx.exe (.NET Execution Environment). 

 

wwwroot

ASP.NET Core has a new Feature for maintaining wwwroot folder where we put our static contents and libraries so that they are accessible right from the root of the project like HTML files, CSS , image files, and JavaScript files which are sent to the users’ browsers should be stored inside the wwwroot folder.

 Dependencies

There is a special folder called Dependencies which does not present physically but categorically shows the project dependency packages added in the project. Dependencies section is used to manage Bower and NPM tooling packages dependencies in your project. For example, Bower for client-side packages with their dependencies (i.e. jQuery, Bootstrap, Angular). Bower has bower.json file which contains all the packages and dependencies that have installed. So Bower and NPM dependencies appear here in this section. 

 Program.cs class

Program.cs file is the main entry point of our application. As per below code (inside the program.cs), you can see that this class contains a Main() method which looks quite familiar with that you have been seeing in C# Console Apps. This class is used to initiate, build, run the server (IIS and Kestrel) and host the  application. 

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;

namespace FirstASPCoreApplication
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();

host.Run();
}
}
}

 project.json

The first file of our project is project.json. All top level dependencies and libraries that are used by the application are listed in project.json. The project.json file maintains a list of packages used in a project, known as a package reference format.

 Startup.cs Class

The startup class is helpful to define the request handling pipeline and configure the Services required by the app. It has 2 methods ConfigureServices() and Configure(). This class basically is used to configure middle-wares on the request pipeline. The Startup class(Startup.cs) is where application pipeline is configured for request processing.

Web.config

In the previous versions, everything is handled by Web.Config but in ASP.NET Core, we don’t know about Web configure file and the only purpose it gives the instruction to iis for what should be done and it receives the http request.

What do you think?

I hope you have overview about ASP .NET Core Layout/structure of the Application. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

 

Powershell : How to Compare Two Files, and List Differences

What is Compare-Object cmdlet do?

The Compare-Object cmdlet compares two sets of objects. One set of objects is the “reference set,” and the other set is the “difference set”. The below format will be out of the comparison.

<= This indicates that property value appears only in the -ReferenceObject set.
=> Indicates that property value appears only in the -differenceObject.
== Indicates that both property value appears the same.

Example:

In the Compare-Object cmdlet, there are two required parameters -referenceObject and -differenceObject. For example, -referenceObject controls the master content, the file which holds all the information, while -differenceObject has the secondary file.

Demo

Let we create two files, the first (Master & Child list) is for reference and the second for comparison. Now we are ready to execute this Compare-Object script.

MasterList.txt

WaterMelon
Grapes
Mango
Oranges
Bananas
Cucumber
Guva

ChildList.txt

Mango
Apple
Oranges
Bananas
Cucumber
WaterMelon
Grapes

Example 1: To Compare Two Files, and List Their Differences

This command compares the contents of two text files. Here Apple is present in the second file (-differenceObject set) not in the first file (-ReferenceObject set)  so the output will be => and Guva is present in the first file and not in the second file, so the output will be <=.

Clear-Host
$strReference = Get-Content "D:\BLOG\Power Shell\Examples\Masterlist.txt"
$strDifference = Get-Content "D:\BLOG\Power Shell\Examples\ChildList.txt"
Compare-Object $strReference $strDifference

Example 2: To Compare Two Files, with -Parameters

Clear-Host
$strReference = Get-Content "D:\BLOG\Power Shell\Examples\Masterlist.txt"
$strDifference = Get-Content "D:\BLOG\Power Shell\Examples\ChildList.txt"
Compare-Object $strReference $strDifference -IncludeEqual

Optional Parameters

Optional Parameters

-CaseSensitive This indicates that comparisons should be case-sensitive.
-Culture Specifies the culture to use for comparisons.
-Property Specifies an array of properties of the reference and difference objects to compare.
-ExcludeDifferent Indicates that this cmdlet displays only the characteristics of compared objects that are equal
-SyncWindow Specifies the number of adjacent objects that this cmdlet inspects while looking for a match in a collection of objects.
-IncludeEqual Indicates that this cmdlet displays characteristics of compared objects that are equal. By default, only characteristics that differ between the reference and different objects are displayed.
-PassThru Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

 

NOTE: If the reference set or the difference set is null ($null), Compare-Object generates a terminating error.

 

What do you think?

I hope you have got an idea about how to use PowerShell Compare-Object cmdlet. I would like to have feedback from the readers of my post. Your valuable feedback, question, or comments about this article are always welcome.

PowerShell : Continue Keyword

Continue Keyword in PowerShell

One of the things that is a bit confusing for powershell beginner is the Continue statement. This is partially because it does not act like it might in some other languages. Next question will arise, then what does the Continue statement do in Windows PowerShell? the answer is it returns flow to the top of the innermost loop that is controlled by a WhileFor, or Foreach statement. 

Example:

In the following example, program flow returns to the top of the While loop if value of $myValue variable is equal to 6. As a result, all the numbers between 1 and 10 are displayed except for 5:

while ($myValue -lt 10)
{
$myValue += 1
if ($myValue -eq 6) {Continue}
Write-Host $myValue 
}

Output:

1
2
3
4
5
7
8
9
10

The Continue keyword supports labels. A label is a name you assign to a statement in a script, so the continue will skip in the current loop and execute form the  assigned label location. Let we discuss more about the labels in upcoming articles.

ASP.NET Core Real Power: Features And Benefits

Introduction

ASP.NET Core 1.0 is not a continuation of ASP.NET 4.6. It is a whole new framework, a side-by-side project which happily lives alongside everything else we know. It is an actual re-write of the current ASP.NET 4.6 framework, but much smaller and a lot much more modular. There is no System. Web namespace anymore and everything which came with it.

It is the framework you want to use for web development with .NET. ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. If you have any experience with MVC or Web API over the last few years, you will notice some familiar features. ASP.NET Core 1.0 is a 1.0 release that includes Web API and MVC but doesn’t have SignalR or Web Pages. It doesn’t yet support VB or F#.

If you have any experience with MVC or Web API over the last few years, you will notice some familiar features.This sequence of tutorials, will help you write an application using ASP.NET Core that can create, edit, and view data from a database.

Advantages of ASP.NET Core

Open Source:

ASP.NET Core is open source and available on GitHub,Which help to reduce the cost of hosting.NET application.

Platform Independent (Cross Platform Support):

ASP.NET Core 1.0 is a big fundamental change to the ASP.NET landscape and it is open source. ASP.NET Core is supported on Windows, Mac and Linux OSX

Built from scratch:

ASP.NET Core is not like an enhancement to ASP.NET 4.5 but it has been built from scratch. A lot of new features have been added to it and some of the existing features has been dropped also. To support Cross Platform and improve performance some existing features have been removed.

Modular Web Framework:

Asp.Net core everything is managed using nugget package, so it’s easy to upgrade new framework without releasing new .net framework version. In ASP.NET Core, a community can just release new NuGet package version and you will get latest changes by updating your packages. The .NET developer has the ability to pick and choose which ASP.NET features to include in their solutions. This opt-in model allows developers to be more deliberate with regard to which libraries are included in their projects

Dependency Injection:

Dependency injection is integrated into the framework for achieving loose coupling between objects and their collaborators.Third party products such as Autofac should still be available as an alternative to the build-in ASP.NET DI functionality.

Combination of MVC and WEB.API

In previous versions of ASP.NET, MVC and WEB.API were based on different versions of the framework ie., System.Web.Mvc and System.Web.Http/System.Net.Http, respectively. This has been removed and its been integrated with ASP.NET CORE 1.0 MVC 6. There is now a single set of objects within a single namespace (Microsoft.AspNet.Mvc). This standardized approach simplifies developing both MVC and WEB.API endpoints.

What do you think?

I hope you have basic about ASP .NET Core and its advantage . I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

Introduction to ASP.NET Core

Introduction

ASP.NET Core is the new web framework from Microsoft. It is the framework you want to use for web development with .NET. ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-based, Internet-connected applications. If you have any experience with MVC or Web API over the last few years, you will notice some familiar features.

ASP.NET Core 1.0 is a 1.0 release that includes Web API and MVC but doesn’t have SignalR or Web Pages.
It doesn’t yet support VB or F#.

What is ASP.NET Core

ASP.NET Core is an open source and cloud-optimized web framework for developing modern web applications that can be developed and run on across the many platforms like Windows, Linux and the Mac. It includes the MVC framework, which now combines the features of MVC and Web API into a single web programming framework.

What is New in ASP.NET Core?

ASP.NET Core ships entirely as NuGet packages. This allows you to optimize your application to include only the necessary NuGet packages rather than having all in application.

  • Open-source and community-focused.
  • A lightweight, high-performance, and modular HTTP request pipeline.
  • Ability to build and run on Windows, macOS, and Linux.
  • Ability to host on IIS, Nginx, Apache, Docker, or self-host in your own process.
  • ASP.NET Core apps can run on .NET Core or on the full .NET Framework.

What do you think?

I hope you have basic introduction and overview about ASP .NET Core. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

 

Power Shell – Containment Operators

Power Shell Containment Operators

The containment operators (-contains and -notcontains) are similar to the equal operators. However, the containment operators always return a Boolean value, even when the input is a collection. The conditional operator -Contains is similar to -eq, except it returns ‘True’ or ‘False’. -Contains is designed for situations where you wish to test for one particular item in a collection, array or a hash table.

Operators Description
-contains Returns true when reference value contained in a collection
-notcontains Returns true when reference value not contained in a collection
-in Returns true when test value contained in a collection
-notin Returns true when test value not contained in a collection

contains

Always returns a Boolean value. Returns TRUE only when the test value exactly matches at least one of the reference values. When the test value is a collection, the Contains operator uses reference equality. It returns TRUE only when one of the reference values is the same instance of the test value object.

Syntax: <Reference-values> -contains <Test-value>

Example: 1

Contains checks each item between the commas

$Name = "John", "Ray Matt", "Anthony" 
$Name -Contains "Ray Matt"

OUTPUT

True

Example: 2

-Contains requires exact equality

$Name = "John", "Ray Matt", "Anthony" 
$Name -Contains "Ray"

OUTPUT

False

-notcontains

The negative -NotContains is not as useful as -NotMatch. However, from what we have already learned the syntax is predictable.

Syntax: <Reference-values> -notcontains <Test-value>

Example:

$Name = "John", "Ray Matt", "Anthony" 
$Name -notContains "Ray"

OUTPUT

True

-in Operator

In operator return the boolean value if the test value appears in a collection of reference values. Always return as Boolean value. Returns TRUE only when the test value exactly matches at least one of the reference values else it will returns FALSE.

Syntax: <Test-value> -in <Reference-values>

Example: 1

$Name = "John", "Ray Matt", "Anthony" 
"Ray" -in $Name

Output:

False

Example: 2

$Name = "John", "Ray Matt", "Anthony" 
"Ray Matt" -in $Name

Output:

True

-notin Operator

In operator return the boolean value if the test value appears in a collection of reference values. Always return as Boolean value. Returns TRUE only when the test value not a exactly matches at least one of the reference values else it will returns FALSE.

Syntax: <Test-value> -notin \<Reference-values>

Example: 1

$Name = "John", "Ray Matt", "Anthony" 
"Ray" -in $Name

Output:

True

Example: 2

$Name = "John", "Ray Matt", "Anthony" 
"Ray Matt" -in $Name

Output:

False

PowerShell : Do-While & Do-Until Loop

Do-While & Do-Until Loop in PowerShell

Loops are an essential construct in any programming language as they enable a block of code to be repeatedly executed based on the condition. This can be useful for iterating through items in an object or repeatedly performing an operation. PowerShell supports involves setting a condition which either allows the loop to process as long as the condition is true or until it is met. 

  • The Do keyword works with the While keyword or the Until keyword to run the statements in a script block, up to the condition. The script block in a Do loop always runs at least once.
  • In a Do-While loop, the condition is evaluated after the script block has run. Then the while loop repeat the script until as long as the condition became false.
  • In a Do-Until loop always runs at least once before the condition is evaluated. However, the script block runs as long as the condition is false.

Do-While

Syntax : do {<statement list>} while (<condition>)

Example:

In below example, the loop will stop executing if condition became false that is if loop_index value reach 0 then condition became false.

$myArray = 1,2,3,0,4
do
{
$loop_index++;
}
while ($myArray[$loop_index] -ne 0)
$loop_index

Output:

3

Do-Until

Syntax : do {<statement list>} until (<condition>)

Example:

In below example, Do…Until loop is used when we want to repeat a set of statements as long as the condition is false.

$myArray = 1,2,3,0,4
do
{
$loop_index++;
}
until($myArray[$loop_index] -ne 0)
$loop_index

Output:

4

 

Power Shell – Type comparison

What is comparison Operator?

Comparison operators let you specify conditions for comparing values and finding values that match specified patterns. To use a comparison operator, specify the values that you want to compare together with an operator that separates these values.

Type comparison

The type comparison operators (-is and -isnot) are used to determine if an object is a specific type.

Operators  Description
-is Returns true if both object are the same type
-isnot Returns true if the objects are not the same type

-is Operator

Syntax: <object> -is <type reference>

Example:

PS C:\>
$stringMsg1 = "dotnet-helpers"
$stringMsg2 = 100
$stringMsg1 -is $stringMsg2.GetType()
$stringMsg2 -is [int]

OUTPUT

False
True

-isnot Operator

Syntax: <object> -is <type reference>

Example:

PS C:\>
$stringMsg1 = "dotnet-helpers"
$stringMsg2 = 100
$stringMsg1 -isnot $stringMsg2.GetType()
$stringMsg2 -isnot [int]

OUTPUT

True
False