Build ASP.Net Core Razor Page Application

//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js

(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: “ca-pub-4949947405553600”,
enable_page_level_ads: true
});

In this post, I’m going to show how to build ASP.net Core Web Application with Razor Pages.

Razor Pages is a new aspect of ASP.net core MVC, Razor pages make a coding page focused approach to develop web applications.

Prerequisites,

  • Visual Studio.
  • .net Core SDK.

Let’s move to project set up,

Step 01,

  • From the Visual Studio File menu, select New > Project.
  • Create a new ASP.NET Core Web Application. Name the project Store.

1

Step 02,

  • Select ASP.NET Core 2.1 in the drop-down, and then select Web Application.2
  • Then Visual studio template creates a Razor Project.3
  • After Successfully creates the project you can run it.

Step 03,

Now we are going to Connect with Database using Razor App,

We are going to implement App using Entity Framework DB Approach.

To use EF Core, install the package for the database provider(s) you want to target. This walkthrough uses SQL Server. For a list of available providers see Database Providers.

  • Tools > NuGet Package Manager > Package Manager Console
  • Run Install-Package Microsoft.EntityFrameworkCore.SqlServer

We will be using some Entity Framework Tools to create a model from the database. So we will install the tools package as well:

  • Run Install-Package Microsoft.EntityFrameworkCore.Tools

We will be using some ASP.NET Core Scaffolding tools to create controllers and views later on. So we will install this design package as well:

  • Run Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

 

Create a Database Called “StoreDB” & then Create a table called “Product” with following columns,

4.PNG

Then create the Entity Framework model based on your existing database.

  • Tools –> NuGet Package Manager –> Package Manager Console
  • Run the following command to create a model from the existing database:

Scaffold-DbContext “Data Source=295_LP1\SQLEXPRESS2012;Initial Catalog=StoreDB;User ID=sa;Password=123” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

5

 

Step 04,

  • In Solution Explorer, right-click on the Pages folder > Add > New Folder.
  • Name the folder Movies

In Solution Explorer, right-click on the Pages/Movies folder > Add > New Scaffolded Item.

6

Complete the Add Razor Pages using Entity Framework (CRUD) dialog:

  • In the Model class drop down, select Movie (Store.Models).
  • In the Data context class row, select the + (plus) sign and accept the generated name Store.Models.StoreDBContext.
  • In the Data context class drop down, select Store.Models.StoreDBContext
  • Select Add.

7

 

To register as a service, open Startup.cs, and add the highlighted lines to the method.

public void ConfigureServices(IServiceCollection services) { services.AddDbContext<StoreDBContext>(options => options.UseSqlServer(Configuration.GetConnectionString(“DefaultConnection”))); services.AddMvc(); }

Open the appsettings.json file and add a connection string as shown in the following code:

{
“ConnectionStrings”: {
“DefaultConnection”: “Data Source=295_LP1\\SQLEXPRESS2012;Initial Catalog=StoreDB;User ID=sa;Password=123”
},
“Logging”: {
“LogLevel”: {
“Default”: “Warning”
}
},
“AllowedHosts”: “*”
}

 

Now run your project,

Then you can do CRUD operations with Razor Web APP.

8.PNG

Build ASP.net MVC Project with Oracle Data Base using Entity Framework DB first approach

In this article i want to explain how to create ASP.net MVC Application with Oracle Database using Entity Framework DB first approach.

first you have to install visual studio, i’m going to demonstrate using Visual Studio 2015, because at the moment Oracle  provided Oracle Developer tools for Visual  Studio up to visual studio 2015 version. then you have to install Oracle Data base in your local machine or you can access remote Oracle DB.

you can download Oracle Developer tools using this Link

After successfully installing Visual Studio and Oracle Developer tools (ODT), lets go to steps ,

Step 01

Open Visual Studio and Create Empty ASP.net MVC Project.

Step 02

Then you have to install Oracle Managed DataAccess and Oracle Managed DataAccess Entity framework packages using Nuget package manager to your Project.

after successfully installing Oracle Packages you can see those packages inside the references.

Step 03

Then you have to connect oracle Connection to Visual Studio Data Connections by Providing Oracle Connection Properties.

Step 04

Then add ADO.net model to your project, in this process you  have select your connection and Database properties such as Tables , Views etc.

After that it will create Database Context and model entities in side your project.then you will see the Model entity classes inside your project.

Step 05

Then you have to provide password for Web Config connection String, because in Context and Model Generating process it will not provide password for your connection string.

5

Step 06

Now Almost done, you can call Database and Retrieve Values from Database.

i have create new controller and Access connected database using Context (Entities).

6

 

Note : if you get Exception like below while run the application ,

Type is not resolved for member ‘Oracle.ManagedDataAccess.Client’

you have register you oracle Manage data access in Global Assembly Cache (GAC).

Below is the Steps of Register Oracle Managed Data Access in GAC.

Set Path to Oracle Managed Data Access stored in :

C:\Windows\system32>cd E:\ud\packages\Oracle.ManagedDataAccess\

then Run Below command to add GAC

E:\ud\packages\Oracle.ManagedDataAccess\>”C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\gacutil.exe” /i Oracle.ManagedDataAccess.dll

if Successfully Added to GAC you will see below messege in CMD,

Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.33440
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly successfully added to the cache

 

Thanks….

 

Error: Unable to Start Program- An operation is not legal in the current state

Few days back , i have got an error when i’m doing debugging on Visual Studio 2017,

The Error is,

Unable to Start Program – An operation is not Legal in the Current State.

01

the solution is unchecked the java script debugging in Chrome & IE.

Go to Tools in Visual Studio –> Options –> Debugging –> General

2

Happy Coding !

Error: Microsoft Report Viewer item (RDLC) not available to add in Visual Studio 2017

Hi all,

I got this problem when i’m working with Visual Studio 2017. i had requirement to add Microsoft Report Viewer (RDLC) file to my project, but when i go to add new item , there is no any reporting component to add to project.

I do three ways to resolve this issue.,

First :

Run the Visual Studio 2017 Setup file and check SQL Server Data Tools installed or Not.if not please install it.

1

Second:

Install  Microsoft Repo,rt Projects for Visual Studio using below link

Microsoft Report Projects for Visual Studio

after install the Microsoft Report Projects for Visual Studio you can use reporting as separate project.

you can add report project into solution under Business Intelligence category.

3.JPG

Third :

Install Microsoft Rdlc Report Designer for Visual Studio using below link

Microsoft Rdlc Report Designer for Visual Studio

After install Microsoft Rdlc Report Designer,you can add Microsoft Report Viewer File (RDLC) to your project.

4.JPG

If is there any Issue with above steps, feel free to contact me,

 

Thanks,

Udara.

 

Happy Coding !

Visual Studio 2017 Offline Installer

Hi Guys,

Visual studio 2017 offline installer not available in Visual Studio Official Site,there is only online installer for download.so here i have Shared link for Visual Studio 2017 Offline Installer,

Link : https://www.mediafire.com/?37ib8xn2bs7xbjd

Zip password : UdaraDev2017

if is there any issue with installer, please let me know.

Happy Coding !

 

Send Email in SharePoint Online Using SharePoint Client Object Model (CSOM)

HI, Below i have figured how to send Email in SharePoint Online using  SharePoint Client Object Model (CSOM).

In this case i have used “Microsoft.SharePoint.Client.Utilities”

This is a commonly used method to send email. You can use a SharePoint Utility class to send an Email. One downside is that you cannot send to external users. If you are sending to external users they should be added to your mail exchange.  That needs to be done in advance since it will take some time to reflect such changes.

Below is the Simple Code,

using (var EmailclientContext = clientContext)
{
 var emailprpoperties = new EmailProperties();
emailprpoperties .BCC = new List<string> { “udara@udaradevlab.onmicrosoft.com” };
emailprpoperties .To = new List<string> { “udara@udaradevlab.onmicrosoft.com” };
emailprpoperties .From = “testuser@udaradevlab.onmicrosoft.com”;
emailprpoperties .Body = “<b>Hi Udara, You receive a test Mail</b>”;
emailprpoperties .Subject = “Mail Testing”;

Utility.SendEmail(EmailclientContext , emailprpoperties );
EmailclientContext .ExecuteQuery();
}

 

Thanks,

Udara

ASP.NET Form Control Validation using Java Script and JQuery : Validate DropDown List in side the ASP.net Grid View

Here i would like to explain how to validate Drop Down List in side the Grid View,It’s very Simple.

var GridView = document.getElementById(‘<%=Grid.ClientID %>’);

var DropDownArray = new Array();

for (var i = 0; i < DropDownArray .length; i++) { //Looping Dropdown list Array to validate
if (DropDownArray .item(i).value == ‘Pending’) //If dropdown has no selected value
{
//Put Validation Message
return false;
}
}

Thanks…

Create Simple SharePoint Provider Hosted App with Microsoft Azure

This explains you to how to create SharePoint Provider Hosted App with Microsoft Azure,

Prerequisite

  1. Office 365 site (you can create Free trial site from Microsoft).Create Office 365 Account
  2. Microsoft Azure Account ( you can create free trial account from Microsoft).Create Azure Account
  3. Microsoft Visual Studio 2013 or 2015 (I’ll explain with 2013).

Step 01.

Start a new Visual Studio Project, use the “App for SharePoint 2013” template as in the following list.

1

Step 02.

Select the Provider-hosted option for this example. In a Provider-hosted app, application resources will be deployed in a server outside the SharePoint environment.Enter Your SharePoint office 365 site as Debugging App.

2

Step 03.

Select the type of web project you want to Host.I select “ASP.net Web form Application”,this step is most related to development architecture.(Ex. Tiered Architecture or MVC) .

4

Step 04 

In the next step, select “Use Client secret (requires a SharePoint farm connected to ACS)”. We will be using the Access Control Service (ACS) available with Microsoft Azure for this example.Simply Access between Hosted Account (Azure).

5

 

Step 05.

Click “Finish” and the project is created for you by Visual Studio. You can see two projects created under the solution. The first project consists of just an app icon and AppManifest.xml that manages all the settings like start URL, permission, Query strings, Client ID, Tokens and so on.6

Step 06.

The next step is to register a new app using client Id and Client Secret.

  • Go to the “/_layouts/15/appregnew.aspx” page of your SharePoint site (in my case, it is https://udaradev.sharepoint.com) to generate the client Id and client secret id,
  • Click on the generate buttons of Client Id and Client Secret to generate both.

7

Step 07.

We need to fill in “App Domain” and “Redirect URL”. In fact, this is the website where the app is hosted. I am using Microsoft Azure to host my app. Let us go to the Windows Azure Management Portal and create a web site to host your app.

9

Step 08.

This the Web Site I have creted on Azure and credted Azure Site Details.

10

11

Step 09.

Enter Azure Site details on SharePoint App Registration form and press create button, then you will see App Identifier created message.

12

Copy the Client Id and Client Secret to a safe place.

14

Step 10.

The next step is to publish both projects separately. First, publish the app project as in the following

15

Enter Client Id and Client secret in below form and click finish.

16

Step 11.

Click Package your App,then you have to enter Azure Web site url and Client Id. After that Packed App file folder will open as below sreens.

17

Enter Url of Azure Web Site.

18

App file folder Location

19

 

Step 12.

Upload App File to SharePoint Site. You Should upload App file to Developer Site not a Team Site. Go How to Create Developer Site

  • Click New App To Deploy.

20

  • Then it’ll pop up App upload Panel

21

  • Click on Upload link and Upload you packaged App solution.

22

  • After successfully uploaded it’ll pop-up below screen,then press deploy button.

23

  • Now You can see your App on Site contents.

24

Step 13.

Click on App it’ll become server error , because we haven’t deployed the remote web to Microsoft Azure. The next step is to deploy the web app to Azure.

25

Step 14.

Publish the application to Microsoft Azure. Open web.config and update the client ID and Client secret as in the following

26

Step 15.

Then Publish the Web Solution to Azure, You can download Publish Profile settings from Azure Web site Setting.

27

Step 16.

After Successfully published you can retrieve Azure Web Site.

28.JPG
 Step 17.

Finally you click on app on SharePoint you can see app works as below.

30

Another thing get basic idea about App configuration from “AppManifest.xml”,Ex. App Startup page.

31

 

Thanks,

 

What is .Net Frame work ? (A simple description)

The .NET Framework is a  platform created by Microsoft for Software developing.It has lot of versions,new released version is 4.6 (April-2016).

Microsoft Definition: A programming infrastructure created by Microsoft for building, deploying, and running applications and services that use .NET technologies, such as desktop applications and Web services.

.net Architecture

ic15013

  • It is Platform for software Developers.
  • It supports many programming languages ( Ex. Vb.net , C#.net ,Asp.net).
  • It supports cross platform developments (Ex.IOS,Android).
  • It has Integrated Development Environment (IDE) (Ex.Microsoft Visual Studio).
  • .NET Framework also includes the .NET Common Language Run-time (CLR), which is responsible for maintaining the execution of all applications developed using the .NET library.

Common Language Run-time (CLR) is the most important part of the .net framework,simply it converts your source code (c#,VB.net) to  native language (Machine Language).so then source code supports with operating system.

Components of the CLR.

Component-of CLR

1. Class Loader : Is an abstract class. Its purpose is to tell  CLR in what manner a class is to be loaded at runtime.

2. MSIL : Microsoft Intermediate Language is considered to be the lowest form of human readable language. It is CPU independent and includes instructions of how to load, store, initialize objects. JIT converts this MSIL into native code which is dependent on the CPU.

3. Code Manager : Is responsible for managing code at run-time.

4. Garbage Collector : The .NET garbage collector enables high-speed allocation and release of memory for the objects in managed code. Its main aim is proper memory management and optimizing the memory.

5. Security Engine : It ensures all the security restrictions.

6. Type Checker : It enforces the constraints of types. It enforces strictness in type checking.

7. Thread Support : It allows multi-threading.

8. Debug engine : It allows proper debugging of an application.

9. Base class library : It provides all the types that an application need at runtime.

10. Exception manager : Handles all the exception for an application during runtime.

11. COM Marshaller : It provides an option for interoperability for an application.

Steps of Source code compiling 

Step 1- Application code is written using a .NET – compatible language C#.

fig1

Step 2 – Code is compiled into MSIL, which is stored in an assembly (see Figure 1 – 2).

 

fig2

Step 3 – When this code is executed (either in its own right if it is an executable or when it is used from other code), it must first be compiled into native code using a JIT compiler.
fig3

Step 4 – The native code is executed in the context of the managed CLR, along with any other running applications or processes.
fig4

 

Hope you Learned some thing , this is very simple description,refer MSDN to more in detail about .net framework,

Thanks

Send SMS using usb dongle or modem in ASP.net, C#.net and SharePoint

Hi,

Here I would like to explain how to send SMS using USB dongle and modem, In here i have built some custom component to send sms very easily.Just you need call a method.

Steps

01. Download component.

  Download SMS Component

02. Add “UdaraDev.SMSUtility.dll” to Solution reference. 

03. Its very simple, Just insert below code

  • Method definition :

SMSComponent.SendSMS(“Dongle Attached Physical port name”,”Phone Number you want to send SMS”,”Text Message”).

Example. 

SMSComponent.SendSMS(“COM16”, “0711022122”, “HI”);

 

Thanks,